一、在豆瓣電影網(wǎng)爬取影片的短評(píng)以及相關(guān)的信息:
二、參考代碼
import requests
from bs4 import BeautifulSoup
import pandas as pd
url_list = []
for i in range(5):
url_list.append('https://movie.douban.com/subject/26794435/comments?start=%s&limit=20&sort=new_score&status=P'%(i*20))
n = 0
commentInfo_list =[]
for url in url_list:
txt = requests.get(url).text # 網(wǎng)頁的獲取
soup = BeautifulSoup(txt,'lxml') # 網(wǎng)頁的解析
divs = soup.find('div',id='comments').find_all('div',class_='comment')
for div in divs:
comments_dict ={}
comments_dict['用戶名'] = div.find('span',class_ = 'comment-info').find('a').text
comments_dict['評(píng)論時(shí)間'] = div.find('span',class_= 'comment-time').text.replace(' ','').replace('\n','')
comments_dict['有用數(shù)量'] = div.find('span',class_= 'votes').text
comments_dict['評(píng)論內(nèi)容'] = div.find('span',class_='short').text
commentInfo_list.append(comments_dict)
n += 1
print('已成功采集%s條評(píng)論'%n)
df = pd.DataFrame(commentInfo_list)
三、查看爬取下來的短評(píng)以及相關(guān)的信息:
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
