【问题标题】:Splash won't render all contents of pageSplash 不会呈现页面的所有内容
【发布时间】:2017-07-05 01:12:17
【问题描述】:

我正在使用Splash v2.3.2,我正在尝试渲染page,但它并没有渲染所有内容。它不会呈现图像或动态加载的内容。

我正在使用我的http://localhost:8050/ 和脚本:

function main(splash)
  local url = splash.args.url
  assert(splash:go(url))
  assert(splash:wait(10))
  return {
    html = splash:html(),
    png = splash:png(),
    har = splash:har(),
  }
end

这是一个浏览器渲染:

这是 Splash 渲染的截图:

我尝试更改等待时间并尝试允许插件。这些都不行。我假设动态加载的内容受到限制,但我不确定。任何帮助表示赞赏。

【问题讨论】:

    标签: splash-screen scrapy-splash splash-js-render


    【解决方案1】:

    问题在于 localStorage - 站点使用它,但 Splash 默认使用私有模式,这会禁用 localStorage。要修复它,请禁用私有模式(请参阅here)。该脚本适用于我(Splash 3.0):

    function main(splash)
      splash.private_mode_enabled = false
      local url = splash.args.url
      assert(splash:go(url))
      assert(splash:wait(10))
      return {
        html = splash:html(),
        png = splash:png(),
        har = splash:har(),
      }
    end
    

    另见:http://splash.readthedocs.io/en/stable/faq.html#website-is-not-rendered-correctly

    【讨论】:

    • 工作就像一个魅力!
    【解决方案2】:

    我假设您正在尝试抓取属性描述文本。在您的代码中,您刚刚添加了 splash:wait(10),我的建议是您应该尝试实现特定 css 元素的等待。在您的情况下,span#listingpropertydescription。 您可以编写一个函数来等待这个特定元素,然后返回 html 页面。

    注意您可以在http://localhost:8050/ 中找到示例等待元素代码

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-28
      • 2019-01-24
      • 1970-01-01
      • 2011-01-06
      • 2010-11-29
      • 2021-11-07
      • 2013-11-20
      • 2018-02-13
      相关资源
      最近更新 更多