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:
https://www.oddsportal.com/soccer/africa/africa-cup-of-nations-2021/results/ with 4 pages
https://www.oddsportal.com/soccer/africa/caf-confederation-cup-2014/results/ with 2 pages
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
seleniumwhich is a Python library that can interact with dynamic websites, mostly because it's basically a bot - Matiiss