欢迎光临 - 我的站长站,本站所有资源仅供学习与参考,禁止用于商业用途或从事违法行为!

python教程

python爬取豆瓣前250排名电影标题

python教程 我的站长站 2023-08-04 共36人阅读

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)