Python 爬取汽车之家口碑数据的相关代码
时间: 2023-10-10 19:05:09 浏览: 306
以下是Python爬取汽车之家口碑数据的基本代码:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://k.autohome.com.cn/3482/ge0/1-5979-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0.html'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
comments = soup.find_all('div', class_='mouthcon')
for comment in comments:
user_name = comment.find('div', class_='name-text').text.strip()
car_name = comment.find('h4', class_='mouth-title').text.strip()
rating = comment.find('div', class_='score-number').text.strip()
content = comment.find('div', class_='text-con').text.strip()
print(user_name, car_name, rating, content)
```
请注意,此代码仅为演示示例。爬取网站数据可能涉及法律问题,请遵守相关规定,使用合法的方式爬取数据。
阅读全文