使用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)

但是卡在这里不知道该怎么写
向各位大神,谢谢!

讨论数量: 1
Jason990420

前者 html 带有你要的资讯, 后者 html 没有你要的资讯,, 一样的作法, 你应该爬不到的, 也许你可以参考下文 (没确认过)

一篇文章教会你利用Python网络爬虫实现豆瓣电影采集

3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!