翼度科技»论坛 编程开发 python 查看内容

凑个小热闹:python采集《狂飙》评论

10

主题

10

帖子

30

积分

新手上路

Rank: 1

积分
30
2023年首部爆款剧集《狂飙》一度冲上热搜第一,害的我两倍速熬夜看完了。

 
 
“是非面前稍不留神,就会步入万丈深渊,唯有坚守信仰,才能守得初心”

 
 
面对这么多广大网友的讨论,我也来凑上一个热闹
用python爬取《狂飙》评论数据
代码展示
部分代码展示
  1. import requests
  2. import parsel
  3. # 我还录制了详细讲解的视频,直接在这个裙 708525271 自取,包括完整代码
  4. headers = {
  5.     'Cookie': '数据我都删除了,建议用自己的',
  6.     'Host': '',
  7.     'User-Agent': '',
  8. }
  9. for page in range(0, 4000):
  10.     print(page)
  11.     url = f'https://movie.douban.com/subject/35465232/comments?start={page*20}&limit=20&status=P&sort=new_score'
  12.     response = requests.get(url=url, headers=headers)
  13.     select = parsel.Selector(response.text)
  14.     comments = select.css('.comment-item .comment')
  15.     for comment in comments:
  16.         name = comment.css('.comment-info a::text').get()
  17.         try:
  18.             score_str = comment.css('.comment-info .rating::attr(class)').get()
  19.             score = score_str.replace('0 rating', '').replace('allstar', '')
  20.         except:
  21.             score = 0
  22.         comment_time = comment.css('.comment-info .comment-time::text').get().strip()
  23.         vote_count = comment.css('.comment-vote .votes.vote-count::text').get()
  24.         comment_content = comment.css('.comment-content span::text').get()
  25.         print(name, score, comment_time, vote_count, comment_content)
复制代码
 
  1.  
复制代码
效果展示

 
 
不登录的话,只能采集部分,全部评论需要登录后才能爬取。
浏览器数据容易泄密,我都删掉了,大家自己修改一下。
 
 
最后

感谢你观看我的文章~本次航班到这里就结束
来源:https://www.cnblogs.com/hahaa/p/17105263.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

举报 回复 使用道具