我正在尝试webscrap并获得以下html中列出的保险金。
保险 保险使用以下代码,但未获取任何内容。有人可以帮忙吗?我对python相当陌生...
import requests
from bs4 import BeautifulSoup
r = requests.get('https://www.kbb.com/ford/escape/2017/s/?vehicleid=415933&intent=buy-new')
html_soup = BeautifulSoup(r.content, 'lxml')
test2 = html_soup.find_all('div',attrs={"class":"col-base-6"})
print(test2)
答案 0 :(得分:0)
并非您在页面上看到的所有数据实际上都是对该URL的get请求的响应。浏览器在后台提出了许多其他请求,这些请求是由javascript代码发起的。
具体来说,请求保险数据的地址是以下网址:
https://www.kbb.com/vehicles/hub/_costtoown/?vehicleid=415933
这是您需要的工作代码:
import requests
from bs4 import BeautifulSoup
r = requests.get('https://www.kbb.com/vehicles/hub/_costtoown/?vehicleid=415933')
html_soup = BeautifulSoup(r.text, 'html.parser')
Insurance = html_soup.find('div',string="Insurance").find_next().text
print(Insurance)