【发布时间】:2021-03-07 13:22:42
【问题描述】:
我正在尝试发出从特定网站获取数据并在控制台上打印出来的网络请求。 为此,我使用 Beautifulsoup 和 requests。您可以从下面的网站看到 HTML 数据,但我没有得到您在下面看到的 2 个坐标的输出。我不知道是否有必要提一下,网站上的 2 个坐标在不断变化。谢谢你帮助我!
HTML:
<div class="cockpitItem">
<h3>Bodenpunkt</h3>
<p id="gpt">
"42,67° Nord" #Coordinate 1 that I want to get
<br>
"170,38° Ost" #Coordinate 2 that I want to get
</p>
</div>
Python 代码:
url = "https://www.astroviewer.net/iss/de/"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
body = soup.find("p",{"id": "gpt"})
print(f"HTML: {body}")
print(f"Text: {body.text}")
输出:
HTML: <p id="gpt"> <br/> </p> #It finds the right part of the HTML data
Text:
【问题讨论】:
-
我认为问题在于页面在不断更新,我认为 BeatifulSoup 不适合。
标签: python html beautifulsoup python-requests