Python爬取网页==$0无法使用beautifulsoup获取内容

2024-10-05 10:51:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试着用美丽的阳光从当地的湖中刮去湖水的温度。你知道吗

结果源代码(通过在Chorme浏览器中显示源代码)或使用beautifulsoup刮取的内容为空。你知道吗

html source code out of the browser

url = 'https://www.goitzsche-tourismus.de/goitzsche-bitterfeld/specials/172-wassertemperatur/'
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')

txt = soup.find("div", {"id": "pegel"}).get_text()
print('content:', txt, 'should be here')

结果:content: should be here

在Chrome开发工具控制台中,如果我键入$0,我会得到正确的结果。你知道吗

use the developer tool console - result is correct

问:我如何得到温度值? 问:为什么我看不到“基本”源代码中的值?你知道吗

谢谢你的提示


Tags: thetxturlgethere源代码htmlpage
1条回答
网友
1楼 · 发布于 2024-10-05 10:51:18

我刚才回答了一些问题。你知道吗

基本上,站点加载在站点的基本代码中,并通过加载在温度值中。Javascript。他们的代码调用另一个包含这些数据的API。你知道吗

您也可以模拟并可能利用它(从道德上讲,您应该获得自己的API密钥),并解析JSON result。你知道吗

我收到的回复是:

{
    "WWM-002 Pegelturm": {
    "Zeit": "30. Dec 2019 15:00 Uhr",
    "Pegel": "74.64",
    "Temperatur": "5.25"
  }
}

相关问题 更多 >

    热门问题