Scrapy-splash 不呈现来自某个反应驱动站点的动态内容

Scrapy-splash not rendering dynamic content from a certain react-driven site

我很好奇是否有任何飞溅可以从该页面获取动态职位内容 - https://nreca.csod.com/ux/ats/careersite/4/home?c=nreca#/requisition/182

为了让 splash 接收到 URL 片段,您必须使用 SplashRequest。为了让它处理 JS cookie,我不得不使用 lua 脚本。下面是我的环境、脚本和 scrapy 代码。

该网站似乎在 3 'steps':

中呈现
  1. 基本上是空的html带有脚本标签
  2. 以上脚本运行并生成站点 header/footer 并检索另一个脚本
  3. #2 中的脚本运行并结合 JS 设置 cookie 检索动态内容(我想要抓取的作业)

如果您在 URL 上执行简单的 GET(即在邮递员中),您将只会看到第 1 步的内容。随着飞溅,我只得到第 2 步的结果 (header/footer)。我 在 response.cookiejar

中看到了 JS cookie

我无法获取要呈现的动态作业内容(第 3 步)。

环境:

刮擦 1.3.3 scrapy 飞溅 0.72 settings

    script = """
        function main(splash)
          splash:init_cookies(splash.args.cookies)
          assert(splash:go{
            splash.args.url,
            headers=splash.args.headers,
            http_method=splash.args.http_method,
            body=splash.args.body,
            })
          assert(splash:wait(15))

          local entries = splash:history()
          local last_response = entries[#entries].response
          return {
            url = splash:url(),
            headers = last_response.headers,
            http_status = last_response.status,
            cookies = splash:get_cookies(),
            html = splash:html(),
          }
        end
    """

    return SplashRequest('https://nreca.csod.com/ux/ats/careersite/4/home?c=nreca#/requisition/182', 
        self.parse_detail, 
        endpoint='execute',
        cache_args=['lua_source'],
        args={
            'lua_source': script,
            'wait': 10,
            'headers': {'User-Agent': 'Mozilla/5.0'}
        },
    )

这肯定是隐私浏览模式默认启动 运行 的问题(特别是不允许访问 window.localStorage)。这通常会导致 javascript 异常发生。尝试使用 --disable-private-mode 选项启动 splash 或参考此文档条目:http://splash.readthedocs.io/en/stable/faq.html#disable-private-mode.