-
-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added CollectionIterator interface * Added PAGINATION function * Fixed LIMIT clause * Fixed linting issues
- Loading branch information
Showing
18 changed files
with
1,240 additions
and
685 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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' | ||
LET resultItemSelector = '.s-result-item' | ||
LET nextBtnSelector = '#pagnNextLink' | ||
LET vendorSelector = 'div > div > div > div.a-fixed-left-grid-col.a-col-right > div.a-row.a-spacing-small > div:nth-child(2) > span:nth-child(2)' | ||
LET priceSelector = 'div > div > div > div.a-fixed-left-grid-col.a-col-right > div:nth-child(4) > div.a-column.a-span7 > div:nth-child(1) > div:nth-child(3) > a > span.a-offscreen' | ||
LET altPriceSelector = 'div > div > div > div.a-fixed-left-grid-col.a-col-right > div:nth-child(2) > div.a-column.a-span7 > div:nth-child(1) > div:nth-child(3) > a > span.a-offscreen' | ||
|
||
LET result = ( | ||
FOR pageNum IN PAGINATION(amazon, nextBtnSelector) | ||
LIMIT @limit | ||
|
||
LET wait = pageNum > 0 ? WAIT_NAVIGATION(amazon) : false | ||
LET waitSelector = wait ? WAIT_ELEMENT(amazon, resultListSelector) : false | ||
|
||
LET items = ( | ||
FOR el IN ELEMENTS(amazon, resultItemSelector) | ||
LET priceTxtMain = INNER_TEXT(el, priceSelector) | ||
LET priceTxt = priceTxtMain != "" ? priceTxtMain : INNER_TEXT(el, altPriceSelector) | ||
|
||
RETURN { | ||
title: INNER_TEXT(el, 'h2'), | ||
vendor: INNER_TEXT(el, vendorSelector), | ||
price: TO_FLOAT(SUBSTITUTE(priceTxt, "$", "")) | ||
} | ||
) | ||
|
||
RETURN items | ||
) | ||
|
||
RETURN FLATTEN(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.