python爬虫爬取京东脉动评论信息
时间: 2023-10-30 07:09:13 浏览: 129
好的,以下是一个简单的 Python 爬虫代码,用于爬取京东脉动的评论信息:
```python
import requests
from bs4 import BeautifulSoup
def get_comments(page):
url = f'https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=100004272107&score=0&sortType=5&page={page}&pageSize=10&isShadowSku=0&fold=1'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
comments = soup.find_all('div', class_='comment-con')
for comment in comments:
print(comment.find('div', class_='comment-text').text.strip())
if __name__ == '__main__':
for i in range(1, 11):
get_comments(i)
```
请注意,此代码仅供学习和参考,不得用于商业用途。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)