mirror of
https://github.com/MontFerret/ferret.git
synced 2025-01-08 03:13:15 +02:00
e6dd5689b4
* Fixed logger level * Fixed WAITFOR EVENT parser * Added tracing to Network Manager * Updated logging * Swtitched to value type of logger * Added tracing * Increased websocket maximum buffer size * Ignore unimportant error message * Added support of new CDP API for layouts * Switched to value type of logger * Added log level * Fixed early context cancellation * Updated example of 'click' action * Switched to val for elements lookup * Fixed unit tests * Refactored 'eval' module * Fixed SetStyle eval expression * Fixed style deletion * Updated logic of setting multiple styles
39 lines
1.4 KiB
Plaintext
39 lines
1.4 KiB
Plaintext
LET baseURL = 'https://www.amazon.com/'
|
|
LET amazon = DOCUMENT(baseURL, { driver: "cdp" })
|
|
|
|
INPUT(amazon, '#twotabsearchtextbox', @criteria)
|
|
CLICK(amazon, '#nav-search-submit-button')
|
|
WAIT_NAVIGATION(amazon)
|
|
|
|
LET resultListSelector = '[data-component-type="s-search-results"]'
|
|
LET resultItemSelector = '[data-component-type="s-search-result"]'
|
|
LET nextBtnSelector = '.s-pagination-next:not(.s-pagination-disabled)'
|
|
LET priceWholeSelector = '.a-price-whole'
|
|
LET priceFracSelector = '.a-price-fraction'
|
|
|
|
LET result = (
|
|
FOR pageNum IN PAGINATION(amazon, nextBtnSelector)
|
|
LIMIT @pages
|
|
|
|
LET waitSelector = pageNum > 0 ? WAIT_ELEMENT(amazon, resultListSelector) : false
|
|
|
|
LET items = (
|
|
FOR el IN ELEMENTS(amazon, resultItemSelector)
|
|
LET hasPrice = ELEMENT_EXISTS(el, priceWholeSelector)
|
|
LET priceWholeTxt = hasPrice ? FIRST(REGEX_MATCH(INNER_TEXT(el, priceWholeSelector), "[0-9]+")) : "0"
|
|
LET priceFracTxt = hasPrice ? FIRST(REGEX_MATCH(INNER_TEXT(el, priceFracSelector), "[0-9]+")) : "00"
|
|
LET price = TO_FLOAT(priceWholeTxt + "." + priceFracTxt)
|
|
LET anchor = ELEMENT(el, "a")
|
|
|
|
RETURN {
|
|
page: pageNum,
|
|
url: baseURL + anchor.attributes.href,
|
|
title: INNER_TEXT(el, 'h2'),
|
|
price
|
|
}
|
|
)
|
|
|
|
RETURN items
|
|
)
|
|
|
|
RETURN FLATTEN(result) |