setup browser
This commit is contained in:
parent
a32b1ef69b
commit
532386222b
1 changed files with 32 additions and 1 deletions
|
|
@ -10,8 +10,39 @@ import (
|
||||||
"task-processor/internal/shared"
|
"task-processor/internal/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (s *Parser) 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 {
|
||||||
|
log.WithError(err).Error(logHeader + logGetPrice + "failed to get single price tag")
|
||||||
|
return copyright, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return copyright, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Parser) HandleTasks(ctx context.Context, tasks []shared.Task, sender chan shared.TaskResult, state *appState.State) {
|
func (s *Parser) HandleTasks(ctx context.Context, tasks []shared.Task, sender chan shared.TaskResult, state *appState.State) {
|
||||||
log.Infof("%v %v handling tasks", logHeader, logWorker)
|
log.Infof("%v Start handling tasks", logHeader)
|
||||||
|
log.Infof("%v Setting up browser", logHeader)
|
||||||
|
cr, err := s.setupBrowser(ctx)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error(logHeader + logGetPrice + "failed to setup browser")
|
||||||
|
}
|
||||||
|
log.WithField("Copyright message", cr).Infof("%v Finished setting up browser.", logHeader)
|
||||||
|
|
||||||
|
log.Infof("%v %v processing tasks...", logHeader, logWorker)
|
||||||
|
|
||||||
allocCtx, allocCancel := chromedp.NewRemoteAllocator(ctx, s.externalBrowser)
|
allocCtx, allocCancel := chromedp.NewRemoteAllocator(ctx, s.externalBrowser)
|
||||||
defer allocCancel()
|
defer allocCancel()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue