2026-04-03 20:54:10 +03:00
|
|
|
package scrapper
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"github.com/chromedp/chromedp"
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (s *Scrapper) setupBrowser(ctx context.Context) (string, error) {
|
|
|
|
|
allocCtx, allocCancel := chromedp.NewRemoteAllocator(ctx, s.externalBrowser)
|
|
|
|
|
defer allocCancel()
|
|
|
|
|
|
|
|
|
|
pageCtx, pageCancel := chromedp.NewContext(allocCtx, chromedp.WithLogf(func(string, ...any) {}))
|
|
|
|
|
defer pageCancel()
|
|
|
|
|
|
|
|
|
|
copyright := "No copyright div found."
|
|
|
|
|
|
|
|
|
|
if err := chromedp.Run(pageCtx,
|
|
|
|
|
chromedp.Navigate("https://www.mandarake.co.jp/"),
|
|
|
|
|
chromedp.WaitReady("body", chromedp.ByQuery),
|
|
|
|
|
chromedp.Text(`div.copyright`, ©right, chromedp.ByQuery, chromedp.AtLeast(0)),
|
|
|
|
|
chromedp.Navigate("https://www.mandarake.co.jp/index2.html"),
|
|
|
|
|
chromedp.WaitReady("body", chromedp.ByQuery),
|
|
|
|
|
); err != nil {
|
2026-04-08 12:17:25 +03:00
|
|
|
log.WithError(err).Error(pkgLogHeader + "failed to setup browser")
|
2026-04-03 20:54:10 +03:00
|
|
|
return copyright, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return copyright, nil
|
|
|
|
|
}
|