Scrapy Splash: Lua script is not clicking on button

27 Views Asked by At

I am trying to execute a simple lua script on my localhost (http://localhost:8050) but due to some reason it is not working. I am new to lua so can you please check it?

function main(splash)
            local url = splash.args.url
            assert(splash:go(url))
            assert(splash:wait(2))
            

            local get_element_dim_by_xpath = splash:jsfunc([[
                function(xpath) {
                    var element = document.evaluate(xpath, document, null,
                        XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
                    var element_rect = element.getClientRects()[0];
                    return {"x": element_rect.left, "y": element_rect.top}
                }
            ]])
            
            local year_drop_dimensions = get_element_dim_by_xpath(
                                '//a[@id="next_paginate"]')
            splash:set_viewport_full()
            splash:mouse_click(year_drop_dimensions.x, year_drop_dimensions.y)
            splash:wait(1.5)
        
        
            return {
                url = splash:url(),
                html = splash:html()
            }
        end

After executing above code, it is not clicking the next button that I am trying to implement through this lua script.

Website URL: https://www.cars.com/shopping/results/?makes[]=mazda&maximum_distance=30&models[]=mazda-cx_90&page=4&stock_type=new&zip=

PS: I want to do it using lua script only

0

There are 0 best solutions below