在浏览器中:<p class="large bugunku-test-sayisi">116.565</p>在Python结果中:<p class="large bugunku-test-sayisi"></p>Python代码:r = requests.get(f'https://covid19.saglik.gov.tr/')source = BeautifulSoup(r.content,"lxml")test = source.find(attrs={"class":"large bugunku-test-sayisi"})print(test)我不明白问题出在哪里,如果你帮助我,我会很高兴
1 回答
慕沐林林
TA贡献2016条经验 获得超9个赞
某些页面元素是使用 JavaScript 异步填充的。幸运的是,您要查找的数据已嵌入 HTML 中:
import requests
import json
url = "https://covid19.saglik.gov.tr/"
response = requests.get(url)
response.raise_for_status()
begin = response.text.find("var sondurumjson = ") + 19
end = response.text.find(";", begin)
data = json.loads(response.text[begin:end])
print(data[0]["gunluk_test"])
输出:
116.565
>>>
添加回答
举报
0/150
提交
取消