0
votes

I have a lua script that performs click on a website pagination links(next button) multiple times based on the number of pages. The page number differs across the links. Currently, my number of clicks is hardcoded using a for-loop. for i=1,4,1 do. I want to click on the next button link if a page exists without hardcoding it.

Using a while loop, I tried this, but I am getting an error in the last line.

i = 1
while True do
  ###do something
i+= 1

website links example:

  1. https://www.oddsportal.com/soccer/africa/africa-cup-of-nations-2021/results/ with 4 pages

  2. https://www.oddsportal.com/soccer/africa/caf-confederation-cup-2014/results/ with 2 pages

  3. https://www.oddsportal.com/soccer/england/premier-league-2020-2021/results/ with 8 pages



    function main(splash, args)
      my_user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, 
   like Gecko) Chrome/103.0.0.0 Safari/537.36'
      splash:set_user_agent(my_user_agent)
      splash.images_enabled = false
      assert(splash:go(args.url))
      assert(splash:wait(0.5))
      splash:set_viewport_full()
      treat=require('treat')
      result= {}
      for i=1,4,1
        do
        assert(splash:runjs('document.querySelector("#pagination > a:nth- 
 child(7)").click()'))
        assert(splash:wait(2))                
        result[i]=splash:html()
    
      end
      return { splash:url(),
              treat.as_array(result),
               splash:png()}
    end

What does it have to do with Python or JS? - matszwecja
@matszwecja because I am using Python scrapy-splash to scrape a dynamic website and to perform clicks on the website, I need to use JavaScript and Lua. Please the person that downvotes my question should upvote it because this is a problem that can be encountered by someone else. - benjamin olise
there's selenium which is a Python library that can interact with dynamic websites, mostly because it's basically a bot - Matiiss
@Matiiss selenium is slow, I already tried that out. Navigating the website links takes a lot of time using selenium. - benjamin olise