爬取比亚迪新能源汽车的评价 python
时间: 2023-11-24 21:52:40 浏览: 185
以下是爬取比亚迪新能源汽车评价的Python代码:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://www.autohome.com.cn/grade/carhtml/BYD_e5_1.html' # 比亚迪e5的评价页面
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# 获取评价总数和好评率
total_score = soup.find('span', class_='font-score').text # 评价总数
good_rate = soup.find('span', class_='fn-right').text # 好评率
# 获取各项评价指标得分
score_items = soup.find_all('div', class_='score-item')
score_dict = {}
for item in score_items:
name = item.find('dt').text # 评价指标名称
score = item.find('dd').text # 评价指标得分
score_dict[name] = score
# 输出结果
print('评价总数:', total_score)
print('好评率:', good_rate)
print('各项评价指标得分:', score_dict)
```
阅读全文