python爬虫爬取电影信息一页
时间: 2023-05-25 08:01:27 浏览: 71
A:
可以使用Python的requests库和BeautifulSoup库,以下是一个示例代码:
```python
import requests
from bs4 import BeautifulSoup
url = "https://movie.douban.com/top250"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
movies = soup.find_all("div", class_="hd")
for movie in movies:
title = movie.a.span.text.strip()
link = movie.a["href"]
print(title, link)
```
该代码可以爬取豆瓣电影排行榜top250的电影名称和链接,输出结果如下:
```
肖申克的救赎 https://movie.douban.com/subject/1292052/
控方证人 https://movie.douban.com/subject/1296141/
美丽人生 https://movie.douban.com/subject/1292063/
阿甘正传 https://movie.douban.com/subject/1292720/
霸王别姬 https://movie.douban.com/subject/1291546/
...
```
相关问题
python爬虫爬取电影资源
要爬取电影资源,你需要了解一些网站的结构和内容。常见的电影资源网站包括BT天堂、迅雷看看、猫咪等。这些网站都有自己的搜索引擎,可以按照关键词搜索电影资源。
下面是一个简单的Python爬虫示例,可以爬取BT天堂上的电影资源:
```python
import requests
from bs4 import BeautifulSoup
# 搜索关键词
keyword = '复仇者联盟'
# 搜索页面的URL
url = 'https://www.bttt.la/search/{}.html'.format(keyword)
# 发送请求获取页面内容
response = requests.get(url)
# 使用BeautifulSoup解析页面
soup = BeautifulSoup(response.content, 'html.parser')
# 找到搜索结果列表
results = soup.find_all('div', class_='search-item')
# 遍历搜索结果并输出
for result in results:
title = result.find('a', class_='item-title').text.strip()
link = result.find('a', class_='item-title')['href']
size = result.find('span', class_='item-size').text.strip()
print(title, link, size)
```
这个示例中,我们首先指定要搜索的关键词,然后构造搜索页面的URL。我们使用requests库发送请求,得到页面内容,再使用BeautifulSoup解析页面内容。我们找到搜索结果列表,遍历搜索结果,然后输出每个搜索结果的标题、链接和大小。
注意,这个示例只是一个简单的演示,如果你要爬取电影资源,请遵守法律法规,不要侵犯版权。
python爬虫爬取连续页面
要实现Python爬虫爬取连续页面的功能,可以按照以下步骤进行操作:
1. 首先,需要获取豆瓣读书小说类1-10页网址。可以使用引用中提供的代码来获取分页的地址,并将这些地址保存到一个列表中。
2. 接下来,需要定义一个空的列表用于存储获取到的图书信息。可以使用引用中提供的代码来获取每一页的图书信息,并将结果保存到这个列表中。
3. 然后,需要将获取到的图书信息依次存入数据库的表中。可以使用引用中提供的代码来实现将图书信息列表依次存入数据库的功能。
4. 最后,可以打印出相应的提示信息,表示连续页面的爬取已经完成。
综上所述,要实现Python爬虫爬取连续页面的功能,可以按照以上步骤进行操作。