【问题标题】:Scrapy-splash not rendering dynamic content from a certain react-driven siteScrapy-splash 不渲染来自某个反应驱动站点的动态内容
【发布时间】:2018-12-31 03:42:29
【问题描述】:

我很想知道是否有任何飞溅可以从这个页面获取动态工作内容 - https://nreca.csod.com/ux/ats/careersite/4/home?c=nreca#/requisition/182

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

网站似乎分 3 个“步骤”呈现:

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

如果您对 URL 执行简单的 GET(即在邮递员中),您将只能看到第 1 步的内容。飞溅我只得到第 2 步的结果(页眉/页脚)。我确实在 response.cookiejar 中看到了 JS cookie

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

环境:

scrapy 1.3.3 scrapy-splash 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'}
        },
    )

【问题讨论】:

    标签: python reactjs scrapy screen-scraping splash-screen


    【解决方案1】:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-30
    • 2017-12-11
    • 2018-05-30
    • 2017-03-08
    相关资源
    最近更新 更多