使用函数爬取蔚蓝书店上的数据,采集的内容有图书封面、书名、ISBN、作者、价格、出版日期、出版社等
时间: 2023-12-28 09:17:46 浏览: 141
好的,为了实现这个功能,我们需要用到 Python 中的 requests 库和 BeautifulSoup 库,可以先执行以下命令安装:
```
pip install requests beautifulsoup4
```
接下来,我们可以使用以下代码来爬取蔚蓝书店的数据:
```python
import requests
from bs4 import BeautifulSoup
# 爬取的页面
url = 'https://www.bluebook.net.cn/'
# 请求页面
response = requests.get(url)
# 解析页面
soup = BeautifulSoup(response.content, 'html.parser')
# 获取所有图书信息的标签
books = soup.find_all('div', class_='tuijian_book')
# 遍历每个图书标签,获取数据
for book in books:
# 获取图书封面
cover = book.find('img')['src']
# 获取书名
name = book.find('div', class_='book_name').text.strip()
# 获取ISBN
isbn = book.find('div', class_='book_isbn').text.strip()
# 获取作者
author = book.find('div', class_='book_author').text.strip()
# 获取价格
price = book.find('div', class_='book_price').text.strip()
# 获取出版日期
publish_date = book.find('div', class_='book_date').text.strip()
# 获取出版社
publisher = book.find('div', class_='book_publish').text.strip()
# 输出获取的数据
print('封面:', cover)
print('书名:', name)
print('ISBN:', isbn)
print('作者:', author)
print('价格:', price)
print('出版日期:', publish_date)
print('出版社:', publisher)
print()
```
这段代码会输出每个图书的封面、书名、ISBN、作者、价格、出版日期和出版社信息。你可以根据自己的需要,对这些数据进行保存或进一步处理。
阅读全文
相关推荐















