how does scrapy-splash handle infinite scrolling?

前端 未结 2 1232
栀梦
栀梦 2020-12-09 13:25

I want to reverse engineering the contents generated by scrolling down in the webpage. The problem is in the url https://www.crowdfunder.com/user/following_page/80159?

2条回答
  •  生来不讨喜
    2020-12-09 13:38

    Thanks Mikhail, I tried your scroll script, and it worked, but I also notice that your script scroll too much one time, some js have no time too render and is skipped, so I do some little change as follow:

    function main(splash)
            local num_scrolls = 10
            local scroll_delay = 1
    
            local scroll_to = splash:jsfunc("window.scrollTo")
            local get_body_height = splash:jsfunc(
                "function() {return document.body.scrollHeight;}"
            )
            assert(splash:go(splash.args.url))
            splash:wait(splash.args.wait)
    
            for _ = 1, num_scrolls do
                local height = get_body_height()
                for i = 1, 10 do
                    scroll_to(0, height * i/10)
                    splash:wait(scroll_delay/10)
                end
            end        
            return splash:html()
    end
    

提交回复
热议问题