https://movie.douban.com/top250?start=0 start是排名第几 并且 n-1
python爬取豆瓣电影名称、评分
import requests
from bs4 import BeautifulSoup
for i in range (0,10):
url = "https://movie.douban.com/top250?start="+(str(i*25))
#获取网页
response = requests.get(url)
#解析网页
soup = BeautifulSoup(response.text,"html.parser")
movie_list = soup.find_all(name='div',attrs={'class':'info'})
#print(movie_list)
print("\n"+str(i+1)+" 页:\n")
#遍历网页信息
for movie_information in movie_list:
m_name = movie_information.find(name = 'span',class_ = 'title').text
m_score = movie_information.find(name = 'span',class_='rating_num').text
print(m_name+" "+m_score)
在使用requests从网页把源码爬下来之后,需要从网页中提取数据,也就是要对网页有一个解析。
最近在学习解析网页的三种方法,分别是正则表达式‘BeauSoup和lxml。