python爬取猫眼电影
时间: 2023-06-13 16:03:45 浏览: 66
好的,以下是一个简单的 Python 爬取猫眼电影的示例代码:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://maoyan.com/films?showType=3'
response = requests.get(url)
bs_info = BeautifulSoup(response.text, 'html.parser')
for tags in bs_info.find_all('div', attrs={'class': 'movie-hover-info'}):
name = tags.find_all('span', attrs={'class': 'name'})[0].text
tag = tags.find_all('div', attrs={'class': 'movie-hover-title'})[1].text.strip()
time = tags.find_all('div', attrs={'class': 'movie-hover-title'})[3].text.strip()
print("电影名称:{0},类型:{1},上映时间:{2}".format(name, tag, time))
```
这个代码使用了 requests 库向猫眼电影网站发送了一个 GET 请求,然后使用 BeautifulSoup 库解析 HTML 并提取了电影名称、类型和上映时间等信息,并将其输出到控制台。你可以根据自己的需求对代码进行修改。