fix: replaces google-chrome with chromium-browser dep

This commit is contained in:
itsscb 2023-07-24 23:23:46 +02:00 committed by GitHub
parent 75eb7086d7
commit e3e2050cc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

24
main.go
View File

@ -7,6 +7,7 @@ import (
"log"
"net/http"
"os"
"os/exec"
"strings"
"github.com/PuerkitoBio/goquery"
@ -16,13 +17,30 @@ import (
const baseURI = "https://www.rottenacker.de/"
func main() {
// Set up the Chrome headless browser.
ctx, cancel := chromedp.NewContext(context.Background())
// Set the path to the Chromium binary on your Raspberry Pi.
execPath, err := exec.LookPath("chromium-browser")
if err != nil {
log.Fatalf("Chromium binary not found: %v", err)
}
opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.Flag("headless", true),
chromedp.Flag("disable-gpu", true),
chromedp.Flag("no-sandbox", true),
chromedp.Flag("ignore-certificate-errors", true),
chromedp.ExecPath(execPath),
)
ctx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
defer cancel()
ctx, cancel = chromedp.NewContext(ctx)
defer cancel()
// Navigate to the URL and wait for the page to load.
var responseText string
err := chromedp.Run(ctx,
err = chromedp.Run(ctx,
chromedp.Navigate(baseURI+"cgi-seiten/amtsblatt.htm"), // Replace with the URL you want to crawl.
chromedp.WaitVisible("body", chromedp.ByQuery),
chromedp.Evaluate(`document.documentElement.innerHTML`, &responseText),