使用Beautiful Requests爬取豆瓣电影标题和评分
import requests
from bs4 import BeautifulSoup
start=0
result=[]
header={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36'}
for i in range (0,1):
html=requests.get('https://movie.douban.com/top250?start='+str(start)+'&filter=',headers=header)
html.encoding='utf-8'
start+=25
soup=BeautifulSoup(html.text,'html.parser')
for item in soup.find_all('div','info'):
title=item.div.a.span.string
yearline=item.find('div','bd').p.contents[2].string
yearline=yearline.replace('\n','')
yearline=yearline.replace(' ','')
year=yearline[0:4]
rating=item.find('span',{'class':'rating_num'}).get_text()
oneresult=[title,rating,year]
result.append(oneresult)
print(result)
上面是别人写的爬取豆瓣电影 Top 250(https://movie.douban.com/top250)的代码
我想要把它改成用来查询 豆瓣热门电视剧的标题和评分(movie.douban.com/tv/#!ty … 20&page_start=0)
import requests
from bs4 import BeautifulSoup
start=0
result=[]
header={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36'}
for i in range (0,1):
html=requests.get('https://movie.douban.com/tv/#!type=tv&tag=%E6%97%A5%E5%89%A7&sort=time&page_limit=20&page_start='+str(start),headers=header)
html.encoding='utf-8'
start+=20
soup=BeautifulSoup(html.text,'html.parser')
for item in soup.find_all('div','list-wp'):
'不知道怎么写
oneresult=[title,rating,year]
result.append(oneresult)
print(result)
但是卡在这里不知道该怎么写
向各位大神,谢谢!
推荐文章: