jupyter爬虫获取豆瓣评论
时间: 2024-01-05 17:21:27 浏览: 169
在Jupyter中进行爬虫获取豆瓣评论的步骤如下:
1. 导入所需的库:
```python
import requests
from bs4 import BeautifulSoup
```
2. 发送HTTP请求获取网页内容:
```python
url = 'https://movie.douban.com/subject/1292052/comments?status=P'
response = requests.get(url)
```
3. 使用BeautifulSoup解析网页内容:
```python
soup = BeautifulSoup(response.text, 'html.parser')
```
4. 找到评论所在的HTML元素,并提取评论内容:
```python
comments = soup.find_all('span', class_='short')
for comment in comments:
print(comment.text)
```
完整的代码如下:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://movie.douban.com/subject/1292052/comments?status=P'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
comments = soup.find_all('span', class_='short')
for comment in comments:
print(comment.text)
```
阅读全文
相关推荐















