This commit is contained in:
parent
45e633a8d0
commit
dc257c195b
1 changed files with 2 additions and 15 deletions
|
|
@ -18,12 +18,11 @@ func (s *Parser) getPrice(ctx context.Context, task shared.Task) (int32, error)
|
||||||
prices []int32
|
prices []int32
|
||||||
)
|
)
|
||||||
|
|
||||||
//get single price
|
|
||||||
if err := chromedp.Run(ctx,
|
if err := chromedp.Run(ctx,
|
||||||
chromedp.Navigate(task.Link),
|
chromedp.Navigate(task.Link),
|
||||||
chromedp.WaitReady("body"),
|
chromedp.WaitReady("body"),
|
||||||
chromedp.WaitVisible(`div.price`, chromedp.ByQuery),
|
chromedp.Text(`div.price`, &singlePrice, chromedp.ByQuery, chromedp.AtLeast(0)),
|
||||||
chromedp.Text(`div.price`, &singlePrice, chromedp.ByQuery),
|
chromedp.Text(`div.price_range`, &rangedPrice, chromedp.ByQuery, chromedp.AtLeast(0)),
|
||||||
); err != nil {
|
); err != nil {
|
||||||
log.WithError(err).Error(logHeader + logGetPrice + "failed to get single price tag")
|
log.WithError(err).Error(logHeader + logGetPrice + "failed to get single price tag")
|
||||||
return zeroPrice, err
|
return zeroPrice, err
|
||||||
|
|
@ -31,23 +30,11 @@ func (s *Parser) getPrice(ctx context.Context, task shared.Task) (int32, error)
|
||||||
singlePrice = strings.TrimSpace(singlePrice)
|
singlePrice = strings.TrimSpace(singlePrice)
|
||||||
prices = append(prices, s.getSinglePriceWithTax(singlePrice))
|
prices = append(prices, s.getSinglePriceWithTax(singlePrice))
|
||||||
|
|
||||||
//get price range
|
|
||||||
if err := chromedp.Run(ctx,
|
|
||||||
chromedp.Navigate(task.Link),
|
|
||||||
chromedp.WaitReady("body"),
|
|
||||||
chromedp.WaitVisible(`price_range`, chromedp.ByQuery),
|
|
||||||
chromedp.Text(`price_range`, &rangedPrice, chromedp.ByQuery),
|
|
||||||
); err != nil {
|
|
||||||
log.WithError(err).Warn(logHeader + logGetPrice + "failed to get ranged price tag")
|
|
||||||
}
|
|
||||||
|
|
||||||
rangedPrice = strings.TrimSpace(rangedPrice)
|
rangedPrice = strings.TrimSpace(rangedPrice)
|
||||||
|
|
||||||
if rangedPrice != "" {
|
if rangedPrice != "" {
|
||||||
prices = append(prices, s.getMinimalPriceFromRangeWithTax(rangedPrice))
|
prices = append(prices, s.getMinimalPriceFromRangeWithTax(rangedPrice))
|
||||||
}
|
}
|
||||||
|
|
||||||
//get minimal price
|
|
||||||
minimal := slices.Min(prices)
|
minimal := slices.Min(prices)
|
||||||
log.Infof(logHeader+"uuid: %s, price: %d", task.MerchUuid, minimal)
|
log.Infof(logHeader+"uuid: %s, price: %d", task.MerchUuid, minimal)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue