本文主要是介绍《python网络爬虫入门实践》笔记:chp3 静态网页抓取(下)实例:豆瓣电影top250,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import requests
from bs4 import BeautifulSoup
def get_movies():
Headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
' Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.44',
'Host': 'movie.douban.com'}
movie_list = []
for i in range(0, 10):
# 构造25页的url
link = "https://movie.douban.com/top250?start=" + str(i * 25) + "&filter="
r = requests.get(link, headers=Headers)
print(str(i + 1), "页面响应状态码", r.status_code)
soup = BeautifulSoup(r.text, "html.parser")
div_list = soup.find_all("div", class_="hd")
for each in div_list:
movie = each.a.span.get_text()
movie_list.append(movie)
return movie_list
movies = get_movies()
print(movies)
这篇关于《python网络爬虫入门实践》笔记:chp3 静态网页抓取(下)实例:豆瓣电影top250的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!