17.splash_case02
生活随笔
收集整理的這篇文章主要介紹了
17.splash_case02
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
# 抓取《我不是藥神》的豆瓣評論import csv
import time
import requests
from lxml import etreefw = open('douban_comments.csv', 'w')
writer = csv.writer(fw)
writer.writerow(['comment_time','comment_content'])for i in range(0,20):# url = 'http://localhost:8050/render.html?url=https://movie.douban.com/subject/26752088/comments?start={}&limit=20&sort=new_score&status=P&timeout=30&wait=0.5'.format(i*20)url = 'https://movie.douban.com/subject/26752088/comments?start={}&limit=20&sort=new_score&status=P'.format(i*20)response = requests.get(url)tree = etree.HTML(response.text)comments = tree.xpath('//div[@class="comment"]')for item in comments:comment_time = item.xpath('./h3/span[2]/span[contains(@class,"comment-time")]/@title')[0]comment_time = int(time.mktime(time.strptime(comment_time,'%Y-%m-%d %H:%M:%S')))comment_content = item.xpath('./p/span/text()')[0].strip()print(comment_time)print(comment_content)writer.writerow([comment_time,comment_content])
轉載于:https://www.cnblogs.com/hankleo/p/10807744.html
總結
以上是生活随笔為你收集整理的17.splash_case02的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MyBatis 与 Hibernate
- 下一篇: jbdc总结