鱼C论坛

 找回密码
 立即注册
查看: 2277|回复: 2

[作品展示] 豆瓣电影爬取前200条评论

[复制链接]
发表于 2022-2-12 16:28:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

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

x
代码比较简单,不做注释了
  1. import requests,json,bs4
  2. from bs4 import BeautifulSoup
  3. q=1
  4. for page in range(0,200,20):
  5.     url= "https://movie.douban.com/subject/35376457/comments?percent_type=&start={}&limit=20&status=P".format(page)
  6.     headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0'}
  7.     res=requests.get(url=url,headers=headers)
  8.     #s = json.loads(res.text)
  9.     soup = BeautifulSoup(res.text, 'html.parser')
  10.     for each in soup.select('div[class="comment"]'):
  11.         s1 = each.select('span[class="comment-time"]')[0].get_text().replace('\n','').replace(' ','')[:10]
  12.         s2 = each.select('span[class="votes vote-count"]')[0].get_text()
  13.         s3 = each.select('span[class="comment-info"]')[0].get_text().split('\n')[1]
  14.         s4 = each.select('span[class="short"]')[0].get_text().replace('\n','')
  15.         s5 = each.select('span[class="comment-info"]')[0].select('span')[1].attrs['title']
  16.         print(q,s5,s1,s2,s3,s4)
  17.         q += 1
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-2-12 16:30:42 | 显示全部楼层
运行结果
微信截图_20220212162925.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-2-12 17:10:24 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-23 02:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表