import requests from bs4 import BeautifulSoup headers = { 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' } for x in range(0,226,25): response = requests.get(f'https://movie.douban.com/top250?start={x}&filter=', headers=headers) html = response.text soup = BeautifulSoup(html, 'lxml') div_list = soup.select('.grid_view>li>.item') for div in div_list: title = div.select_one('.title').text comment = div.select('.star>span')[-1].text score = div.select_one('.star>.rating_num').text others = div.select_one('.bd>.').text print(title, comment, score , others)
day17hw
最新推荐文章于 2024-08-22 22:01:15 发布