1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/examples/pagination.fql

40 lines
1.5 KiB
Plaintext
Raw Normal View History

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'
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
LET result = (
2019-01-12 04:08:59 +02:00
FOR pageNum IN 1..pages
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)
RETURN {
title: INNER_TEXT(el, 'h2'),
2019-01-12 19:21:38 +02:00
vendor,
price
}
)
RETURN items
)
2019-01-12 04:08:59 +02:00
RETURN FLATTEN(result)