用爬虫爬取猫眼电影榜单前100数据
时间: 2023-09-14 15:16:01 浏览: 167
好的,以下是使用Python的爬虫代码:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://maoyan.com/board/4'
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.text, 'html.parser')
movies = soup.find_all('div', class_='movie-item-info')
for index, movie in enumerate(movies):
title = movie.find('a').text
star = movie.find('p', class_='star').text.strip()[3:]
time = movie.find('p', class_='releasetime').text.strip()[5:]
score = movie.find('p', class_='score').text.strip()
print(f'排名:{index+1}')
print(f'电影名称:{title}')
print(f'主演:{star}')
print(f'上映时间:{time}')
print(f'评分:{score}')
print('-'*60)
```
执行代码后,将会输出猫眼电影榜单前100的电影信息。
阅读全文