price scrapper
This commit is contained in:
parent
d19f5f7621
commit
8922b8a4f0
7 changed files with 426 additions and 0 deletions
30
internal/scrapper/helper.go
Normal file
30
internal/scrapper/helper.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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 {
|
||||
log.WithError(err).Error(pkgLogHeader + logGetPrice + "failed to get single price tag")
|
||||
return copyright, err
|
||||
}
|
||||
|
||||
return copyright, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue