github.com/MontFerret/ferret@v0.18.0/examples/pagination_uncontrolled.fql (about)

     1  LET baseURL = 'https://www.amazon.com/'
     2  LET amazon = DOCUMENT(baseURL, { driver: "cdp" })
     3  
     4  INPUT(amazon, '#twotabsearchtextbox', @criteria)
     5  CLICK(amazon, '#nav-search-submit-button')
     6  
     7  WAITFOR EVENT "navigation" IN amazon
     8      FILTER current.url =~ "www\.amazon\.com\/s\?k="
     9      TIMEOUT 50000
    10  
    11  LET resultListSelector = '[data-component-type="s-search-results"]'
    12  LET resultItemSelector = '[data-component-type="s-search-result"]'
    13  LET nextBtnSelector = '.s-pagination-next:not(.s-pagination-disabled)'
    14  LET priceWholeSelector = '.a-price-whole'
    15  LET priceFracSelector = '.a-price-fraction'
    16  
    17  LET result = (
    18      FOR pageNum IN PAGINATION(amazon, nextBtnSelector)
    19          LIMIT @pages
    20  
    21          LET waitSelector = pageNum > 0 ? WAIT_ELEMENT(amazon, resultListSelector) : false
    22  
    23          LET items = (
    24              FOR el IN ELEMENTS(amazon, resultItemSelector)
    25                  LET hasPrice = ELEMENT_EXISTS(el, priceWholeSelector)
    26                  LET priceWholeTxt = hasPrice ? FIRST(REGEX_MATCH(INNER_TEXT(el, priceWholeSelector), "[0-9]+")) : "0"
    27                  LET priceFracTxt = hasPrice ? FIRST(REGEX_MATCH(INNER_TEXT(el, priceFracSelector), "[0-9]+")) : "00"
    28  		        LET price = TO_FLOAT(priceWholeTxt + "." + priceFracTxt)
    29  		        LET anchor = ELEMENT(el, "a")
    30  
    31                  RETURN {
    32                      page: pageNum,
    33                      url: baseURL + anchor.attributes.href,
    34                      title: INNER_TEXT(el, 'h2'),
    35                      price
    36                  }
    37          )
    38  
    39          RETURN items
    40  )
    41  
    42  RETURN FLATTEN(result)