我正试图通过网络诈骗并获得下面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)
并非您在页面上看到的所有数据实际上都是对此URL的get请求的响应。浏览器在后台还有许多其他请求,这些请求都是由javascript代码发起的。
具体来说,对保险数据的请求是通过以下URL发出的:
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)