0

That is the URL: https://www.zebrafell.de/starkwind_check.html I want to extract (for my weather page):
Letzte Aktualisierung: Mo, 07. Jun, 21:31
Ammersee
Amtliche WARNUNG vor STARKWIND
Mo, 07. Jun, 20:37 Uhr
Es treten Gewitter und Windböen mit Geschwindigkeiten um 45 km/h (13m/s, 25kn, Bft 6) auf.
That ist the relevant clip from the webpage:

...<body><div id="main"><div id="wettertab">
<p><strong>Letzte Aktualisierung: Mo, 07. Jun, 21:31 Uhr</strong></p>
<h1 id="Bayern">Bayern</h1>
<h2 id="Ammersee">Ammersee</h2>
<table>..<thead>
<tr><th>Schlagzeile</th><th>G&uuml;ltig von</th><th>G&uuml;ltig bis</th><th>Beschreibung</th></tr></thead>
<tr><td>Amtliche WARNUNG vor STARKWIND</td><td>Mo, 07. Jun, 20:37 Uhr</td><td></td><td>Es treten Gewitter und Windb&ouml;en mit Geschwindigkeiten um 45 km/h (13m/s, 25kn, Bft 6) auf.
</td></tr></table>...

I have not found the right way to solve it... (its my first time - I tried with got and JSDOM)

 const vgmUrl = "https://www.zebrafell.de/starkwind_check.html";
 const response = await got(vgmUrl);
 const dom = new JSDOM(response.body);
 console.log("test", dom.window.document.querySelectorAll("Ammersee"));

But the results are alway empty...I even cannot find "Ammersee"?! Maybe someone has a minute to show me the basics... Thanks a loz (I am tired for try and error)

GeorgB
  • 17
  • 1
  • 7
  • Personally I would use Puppeteer library for web scraping but you can get some inspiration from this post here https://stackoverflow.com/questions/58052001/get-html-source-code-from-a-website-and-then-get-an-element-from-the-html-file – DVN-Anakin Jul 01 '21 at 20:03
  • Also why do you have `querySelectorAll("Ammersee")` instead of `querySelectorAll("#Ammersee")` ? – DVN-Anakin Jul 01 '21 at 20:08

1 Answers1

0

How I would do it with the Puppeteer library:

const puppeteer = require('puppeteer');     // First line
const browser = await puppeteer.launch();

const page = await browser.newPage();
await page.goto('https://www.zebrafell.de/starkwind_check.html');

const myElement = await page.evaluate(() => {
   return document.getElementById('Ammersee').outerHTML;
});

console.log(myElement);

await browser.close();

If you want a working demo copy all my code without the first line and paste it here https://try-puppeteer.appspot.com/, then click on RUN IT

DVN-Anakin
  • 1,549
  • 1
  • 8
  • 12