老师,我抓取电影《楚门的世界》评论的时候,这里一直报错是怎么回事,网上查也查不到?

来源:1-4 BeautifulSoup库入门

梦飞_fly

2020-07-24 16:42:15

http://img.mukewang.com/climg/5f1a9ec109d8d32f06440285.jpg

写回答

2回答

梦飞_fly

提问者

2020-07-24

#爬取评论,我只爬取了一页

import requests
from bs4 import BeautifulSoup

url_duanping = "https://movie.douban.com/subject/1292064/comments?status=P"
headers = {'user-agent':'my-app/0.0.1'}
request1 = requests.get(url=url_duanping,headers = headers)

soup = BeautifulSoup(request1.text,'html.parser')
#print(soup.title.text)
div_comment = soup.find_all(class_ = "comment-item")
print(div_comment[0])

for com in div_comment:
   username = com.find(class_='avatar').a['title']
   comment_time = com.find(class_='comment-time')['title']
   votes = com.find(class_='votes').get_text()
   comment = com.p.get_text()
   with open('1.txt', 'a', encoding='utf8') as file:
       file.write('评论人:' + username + '\n')
       file.write('评论时间:' + comment_time + '\n')
       file.write('支持人数:' + votes + '\n')
       file.write('评论内容:' + comment + '\n')




1

梦飞_fly

提问者

2020-07-24

哎 !我找了半天,看到别人写的,是class后面加了一个下划线就可以了:”class_“ 不知道为什么要这样,是区分python中的class类吗?

1
heltaF
h ※ 如果没回答
h020-07-24
共3条回复

人人都能学的数据分析

从0开始学数据分析,未来互联网各岗位的标配技能,产品经理、运营经理、技术人员人人必备,人人必会的的实用技能

1402 学习 · 1133 问题

查看课程