2018-10-09 02:20:40 +02:00
|
|
|
LET amazon = DOCUMENT('https://www.amazon.com/', true)
|
|
|
|
|
|
|
|
INPUT(amazon, '#twotabsearchtextbox', @criteria)
|
|
|
|
CLICK(amazon, '.nav-search-submit input[type="submit"]')
|
|
|
|
WAIT_NAVIGATION(amazon)
|
|
|
|
|
|
|
|
LET resultListSelector = '#s-results-list-atf'
|
2019-01-12 19:21:38 +02:00
|
|
|
LET resultItemSelector = '.s-result-item.celwidget'
|
2018-10-09 02:20:40 +02:00
|
|
|
LET nextBtnSelector = '#pagnNextLink'
|
2019-01-12 19:21:38 +02:00
|
|
|
LET vendorSelector1 = 'div > div:nth-child(3) > div:nth-child(2) > span:nth-child(2)'
|
|
|
|
LET vendorSelector2 = 'div > div:nth-child(5) > div:nth-child(2) > span:nth-child(2)'
|
|
|
|
LET priceWholeSelector = 'span.sx-price-whole'
|
|
|
|
LET priceFracSelector = 'sup.sx-price-fractional'
|
2019-01-12 04:08:59 +02:00
|
|
|
LET pages = TO_INT(INNER_TEXT(amazon, '#pagn > span.pagnDisabled'))
|
2019-01-12 04:25:58 +02:00
|
|
|
|
2018-10-09 02:20:40 +02:00
|
|
|
LET result = (
|
2019-01-12 04:08:59 +02:00
|
|
|
FOR pageNum IN 1..pages
|
2018-10-09 02:20:40 +02:00
|
|
|
LET clicked = pageNum == 1 ? false : CLICK(amazon, nextBtnSelector)
|
|
|
|
LET wait = clicked ? WAIT_NAVIGATION(amazon) : false
|
|
|
|
LET waitSelector = wait ? WAIT_ELEMENT(amazon, resultListSelector) : false
|
|
|
|
|
|
|
|
LET items = (
|
|
|
|
FOR el IN ELEMENTS(amazon, resultItemSelector)
|
2019-01-12 19:21:38 +02:00
|
|
|
LET priceWholeTxt = INNER_TEXT(el, priceWholeSelector)
|
|
|
|
LET priceFracTxt = INNER_TEXT(el, priceFracSelector)
|
|
|
|
LET price = TO_FLOAT(priceWholeTxt + "." + priceFracTxt)
|
|
|
|
LET vendor = ELEMENT_EXISTS(el, vendorSelector1) ? INNER_TEXT(el, vendorSelector1) : INNER_TEXT(el, vendorSelector2)
|
2018-10-11 18:39:03 +02:00
|
|
|
|
|
|
|
RETURN {
|
|
|
|
title: INNER_TEXT(el, 'h2'),
|
2019-01-12 19:21:38 +02:00
|
|
|
vendor,
|
|
|
|
price
|
2018-10-11 18:39:03 +02:00
|
|
|
}
|
2018-10-09 02:20:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
RETURN items
|
|
|
|
)
|
|
|
|
|
2019-01-12 04:08:59 +02:00
|
|
|
RETURN FLATTEN(result)
|