Issue
I'm trying to write a bot that sends an email when there is a warning from the German Weather Service (Deutsche Wetterdienst DWD). This bot will be implemented in Python on my Raspberry Pi.
I want to extract some information from the DWD Website for, let's say, Berlin. The URL could be https://www.dwd.de/DE/wetter/warnungen_gemeinden/warnWetter_node.html?ort=Berlin-Mitte
First I want to extract the latest timestamp (https://i.stack.imgur.com/Ge224.jpg). When I examine the HTML information of this page, I find the corresponding id="HeaderBox" with the required timestamp (https://i.stack.imgur.com/spMQm.jpg).
Unfortunately, this date and time isn't given when I pull the HTML code with Python. So here's my code:
import requests
from bs4 import BeautifulSoup
url = "https://www.dwd.de/DE/wetter/warnungen_gemeinden/warnWetter_node.html?ort=Berlin-Mitte"
r = requests.get(url)
doc = BeautifulSoup(r.text, "html.parser")
doctext = doc.get_text()
print(doctext)
The result is always just "Letzte Aktualisierung: " and an "empty" line, even when I try last_date = doc.find(id="headerBox")
.
I am using the PyCharm IDE (community edition) and Python 3.11.
Any hints or ideas where to look are appreciated.
Best regards, Christian
Solution
I think you could look at the requests sent to the server to fetch warnings. When inspecting the network, I saw these GET request URLs:
https://www.dwd.de/DWD/warnungen/warnapp_gemeinden/json/warnings_gemeinde.json?jsonp=loadWarnings......
The response was
warnWetter.loadWarnings({
"time": 1694012878000,
"warnings": [],
"copyright": "..."
});
The timestamp right there corresponds to the exact time of last update (as I checked) and does not change when the website is reloaded (unless the last update also change).
You can format it and check for yourself. Hope this helps. Cheers.
new Date(1694012878000).toString()
Answered By - Produdez
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.