用python爬取豆瓣盐镇书评并附出代码
时间: 2023-09-12 10:07:57 浏览: 83
好的,这是一个简单的Python爬虫示例,使用BeautifulSoup和requests库来爬取豆瓣盐镇书评:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://book.douban.com/subject/34976958/comments/'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
comments = soup.find_all('span', class_='short')
for comment in comments:
print(comment.text)
```
这个脚本会向豆瓣盐镇书籍的评论页面发送一个HTTP请求,然后使用BeautifulSoup解析HTML响应。我们使用`find_all()`方法来查找所有的评论,然后打印出来。你可以根据自己的需求修改代码来提取其他信息,比如评论的时间、评分等等。需要注意的是,爬取网站的数据涉及到版权和隐私问题,请合法合规使用。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)