import requests
from bs4 import BeautifulSoup
headers = {
"User-Agent":"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36"
}
for start_num in range(0, 250, 25):
response = requests.get(f"https://movie.douban.com/top250?start={start_num}", headers=headers)
html = response.text
soup = BeautifulSoup(html, "html.parser")
all_titles = soup.findAll("span", attrs={"class":"title"})
for title in all_titles:
title_string = title.string
if "/" not in title_string:
print(title_string)
Python爬虫获取豆瓣top250电影名称
于 2024-05-28 17:18:49 首次发布