Python爬取豆瓣前250排名电影标题,通过pip install requests安装requests库 。
话不多说,直接上代码:
import requests
import re
headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188"
}
for i in range(0,226,25):
zxcvzx = f"https://movie.douban.com/top250?start={i}&filter="
response = requests.get(zxcvzx, headers=headers)
a = re.findall("<img width=\"100\" alt=\"(.*?)\"", response.text, re.S)
for vbn in a:
print(vbn)