我目前正在尝试在Python3.6.4下使用BS4的网站上废弃一些数据,但返回的值并不是我所期望的:
import requests
from bs4 import BeautifulSoup
link = "https://www.lacentrale.fr/listing?makesModelsCommercialNames=FERRARI&sortBy=priceAsc"
request = requests.get(link)
page = request.content
soup = BeautifulSoup(page, "html5lib")
price = soup.find("div", {"class" : "fieldPrice sizeC"}).text
print(price)
我应该得到“39900欧元”,但代码返回“47880欧元”。你知道吗
注:即使没有JS,数据也应该是“39900欧元”。你知道吗
谢谢你的帮助!你知道吗
使用
page.text
代替page.content
例如:
.text
自动解码来自服务器的内容此页上的编码声明错误,因此BeautifulSoup被告知使用错误的编码。您可以强制它使用如下正确的编码:
输出:
相关问题 更多 >
编程相关推荐