scrapy + splash:不呈现整页 javascript 数据

scrapy + splash : not rendering full page javascript data

我只是在用 splash 探索 scrapy,我正在尝试从一个电子商务网站上抓取带有产品 ID、名称和价格的所有产品(裤子)数据 gap but I didn't see all the dynamic product data loaded when I see from splash web UI splash web UI(虽然每个请求只加载 16 个项目 - 不知道为什么) 我尝试了以下选项但没有成功

lua_script2 = """ function main(splash)
    local num_scrolls = 10
    local scroll_delay = 2.0

    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
        scroll_to(0, get_body_height())
        splash:wait(scroll_delay)
    end        
    return splash:html()
end"""                 
                              
            yield SplashRequest(
                url,
                self.parse_product_contents,
                endpoint='execute', 
                args={
                        'lua_source': lua_script2,
                        'wait': 5,
                    }
                )
 

谁能解释一下这种行为? p.s :我正在使用 scrapy 框架,我能够从 render.html 解析产品信息(itemid,名称和价格)(但 render.html 只有 16 项信息)

我把脚本更新到下面

function main(splash)
    local num_scrolls = 10
    local scroll_delay = 2.0
    splash:set_viewport_size(1980, 8020)
    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:set_viewport_full()
    splash:wait(10)
    splash:runjs("jQuery('span.icon-x').click();")
    splash:wait(1)
    for _ = 1, num_scrolls do
        scroll_to(0, get_body_height())
        splash:wait(scroll_delay)
    end      

      splash:wait(30)

    return { 
        png = splash:png(),
        html = splash:html(),
        har = splash:har()
       }
end

并且 运行 它在我的本地启动画面中,png 不能正常工作但是 HTML 有最后一个产品

唯一的问题是电子邮件订阅弹出窗口不会滚动,所以我添加了代码来关闭它