一、问题描述:想用Python 的BeautifulSoup 爬取网站 https://www.guazi.com/www/bmw/o2c-2/#bread页面中车辆的车型名称、年份、里程、价格等信息,但是选择了好多标签和属性值,都无法爬取到想要的信息。
二、 我的代码:
import bs4, requests
headers={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36'}
for i in range(1,2):
url = 'https://www.guazi.com/www/bmw/o'+str(i)+'c-2/#bread'
r = requests.get(url, headers=headers)
bs_r = bs4.BeautifulSoup(r.text, 'html.parser')
uc_status = bs_r.find_all('a', class_='car_a')
for uc in uc_status:
model=uc.find('h2',class_='t').text
print(model)
三、运行代码结果:
Process finished with exit code 0
四、想要请教和解决的问题:
1):麻烦请问该网站是否可以用BeautifulSoup解析?
2):如果可以的话,我的代码是否有问题?
感谢