正在回答 回答被采纳积分+1
#爬取评论,我只爬取了一页
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积分~
来为老师/同学的回答评分吧
0 星