访问https://book.douban.com/top250采集的数据内容:作者、 出版社、 出版年、 页数、 定价、装帧、ISBN、评分、39408人在读、569770人读过、157297人想读
时间: 2023-10-01 17:10:35 浏览: 46
你可以使用 Python 的 requests 库和 BeautifulSoup 库来获取和解析网页内容。以下是一个简单的示例代码,可以爬取豆瓣图书 Top250 的数据:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://book.douban.com/top250'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
for book in soup.select('.item'):
title = book.select('a')[1]['title']
author = book.select('.color-gray')[0].text.split('/')[0].strip()
publisher = book.select('.color-gray')[0].text.split('/')[-3].strip()
pub_date = book.select('.color-gray')[0].text.split('/')[-2].strip()
pages = book.select('.color-gray')[0].text.split('/')[-1].strip()
price = book.select('.price')[0].text.strip()
binding = book.select('.color-gray')[1].text.strip()
isbn = book.select('.color-gray')[0].text.strip().split('ISBN:')[-1]
rating = book.select('.rating_num')[0].text.strip()
read_num = book.select('.pl')[0].text.strip().split('人')[0]
want_num = book.select('.pl')[2].text.strip().split('人')[0]
print('书名:', title)
print('作者:', author)
print('出版社:', publisher)
print('出版年:', pub_date)
print('页数:', pages)
print('定价:', price)
print('装帧:', binding)
print('ISBN:', isbn)
print('评分:', rating)
print('在读人数:', read_num)
print('想读人数:', want_num)
print('--------------------------------------------------')
```
这个示例代码会输出 Top250 中每一本书的信息,包括书名、作者、出版社、出版年、页数、定价、装帧、ISBN、评分、在读人数和想读人数。你可以将代码中的输出部分替换为保存数据的操作,例如写入文件或将数据存入数据库。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)