编写 爬取豆瓣TOP10 电影的 python脚本
时间: 2023-12-18 09:03:43 浏览: 165
python-crawler-douban:豆瓣综合爬虫,使用 `Python-3.7 + Scrapy-1.5` 构建,含豆瓣电影、豆瓣读书、豆瓣音乐三类Top250内容爬取及短评爬取
非常好的问题!以下是实现豆瓣TOP10电影爬取的Python脚本示例:
```python
import requests
from bs4 import BeautifulSoup
url = "https://movie.douban.com/top250"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.content, "html.parser")
movies = soup.find_all("div", class_="hd")
for movie in movies:
print(movie.find("span", class_="title").text)
```
希望对您有帮助!
阅读全文