You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Scrapy-Splash无法渲染React及动态DOM内容的问题求助

问题:Splash无法渲染动态内容及window.onload相关异常
  • 关联StackOverflow问题:Scrapy-splash not rendering dynamic content from a certain react-driven site,向Docker容器传递--disable-private-mode参数后问题仍未解决。

测试场景1:React单页应用异常

我用React编写了一个仅向根节点添加元素的单页应用,代码如下:

function F(){
  class HelloMessage extends React.Component {
    render() {
      return React.createElement(
        "div",
        null,
        "Hello ",
        this.props.name
      );
    }
  }
  return(React.createElement(HelloMessage, { name: "Taylor" }));
}

但Splash返回的页面为空白白屏。

测试场景2:window.onload触发逻辑失效

基于Django搭建的单页网站,在HTML头部加载脚本:

<script src="/static/js/modify-the-dom.js"></script>

脚本内容为:

window.onload = function(){
    document.write('Modified the DOM!');
}

这段代码在常规浏览器中可正常显示内容,但在Splash中,只有移除window.onload包裹、直接执行document.write('Modified the DOM!');才能正常运行——即便我在LUA脚本中设置了约10秒的等待时长,window.onload相关逻辑依然无法触发。

其他异常表现

  • 通过JS检测工具测试发现,当前Splash环境似乎未启用JavaScript。
  • 部分客户端渲染网站(如digikala.com)在Splash中仅返回空白白屏及待AJAX请求填充的空HTML结构;web.archive.org抓取该网站页面时也存在相同的空白问题。

已尝试的Splash配置(无效)

使用的LUA脚本:

function main(splash, args)
    splash:set_user_agent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36")
    assert(splash:go(args.url))
    assert(splash:wait(30)) -- 尝试过不同时长的超时设置
    return {
      html = splash:html(),
      png = splash:png(),
      har = splash:har(),
    }
end

额外添加以下参数后仍无效果:

splash.plugins_enabled = true
splash.resource_timeout = 0

内容的提问来源于stack exchange,提问作者Shayan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 01:00:55