请帮我生成瓜子二手车网站的爬虫代码
时间: 2023-10-01 19:07:29 浏览: 187
好的,以下是瓜子二手车网站的爬虫代码:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://www.guazi.com/www/buy/o1/'
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')
car_list = soup.find('div', {'class': 'carlist clearfix'}).find_all('li')
for car in car_list:
title = car.find('h2', {'class': 't'}).text
price = car.find('div', {'class': 't-price'}).find('p', {'class': 'pri'}).text
mileage = car.find('div', {'class': 't-i'}).find('p', {'class': 'desc-mileage'}).text
print(title, price, mileage)
```
注意:这只是个简单的爬虫代码,可能需要根据具体情况进行修改。同时,爬取网站信息可能违反网站服务协议,请使用时谨慎。
阅读全文