Puppeteer - NodeJS Scraping: Unterschied zwischen den Versionen

Aus Wikizone
Wechseln zu: Navigation, Suche
Zeile 30: Zeile 30:
 
   await browser.close()
 
   await browser.close()
 
}) ();
 
}) ();
 +
</syntaxhighlight>
 +
 +
Starten mit
 +
node index.js
 +
 +
== Beispiel Skripte ==
 +
<syntaxhighlight lang="javascript">
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="javascript">
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="javascript">
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="javascript">
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="javascript">
 
</syntaxhighlight>
 
</syntaxhighlight>

Version vom 17. August 2022, 13:18 Uhr

Quickstart

https://www.youtube.com/watch?v=Sag-Hz9jJNg

Voraussetzung: VisualStudioCode, NodeJS installiert

Ordner erstellen und NodeJS Projekt starten

Terminal

npm init -y
npm install puppeteer

Installiert auch Chromium. Schau mal in die

index.js erstellen. Puppeteer laden mit asynchroner Funktion. Diese Funktion

const puppeteer = require("puppeteer");
(async () => {
}) ();

Beispiel Screenshot von Seite anfertigen:

const puppeteer = require("puppeteer");
(async () => {
  const browser = await puppeteer.launch({headless: false}) // launch can launch headless or with displaying
  const page = await browser.newPage() // open new tab in browser
  await page.goto("https://schlegel.media")
  await page.screenshot({path: "screenshot.png"})

  await browser.close()
}) ();

Starten mit

node index.js

Beispiel Skripte