首页 > 其他 > 详细

17.splash_case02

时间:2019-05-04 11:11:53      阅读:115      评论:0      收藏:0      [点我收藏+]
# 抓取《我不是药神》的豆瓣评论

import csv
import time
import requests
from lxml import etree

fw = 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])

17.splash_case02

原文:https://www.cnblogs.com/hankleo/p/10807744.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!