小编Cas*_*per的帖子

从 Splash 请求中读取 cookie

我在使用 Splash 发出请求后尝试访问 cookie。以下是我构建请求的方式。

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(0.5))

  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
"""
req = SplashRequest(
    url,
    self.parse_page,
    args={
        'wait': 0.5,
        'lua_source': script,
        'endpoint': 'execute'
    }
)
Run Code Online (Sandbox Code Playgroud)

该脚本是 Splash 文档的精确副本。

所以我试图访问网页上设置的cookie。当我不使用 Splash 时,下面的代码将按我的预期工作,但在使用 Splash 时则不然。

self.logger.debug('Cookies: %s', response.headers.get('Set-Cookie'))
Run Code Online (Sandbox Code Playgroud)

使用 Splash 时会返回:

2017-01-03 12:12:37 [蜘蛛] 调试:Cookies:无

当我不使用 Splash 时,此代码可以工作并返回网页提供的 …

python scrapy scrapy-splash splash-js-render

4
推荐指数
1
解决办法
3648
查看次数

标签 统计

python ×1

scrapy ×1

scrapy-splash ×1

splash-js-render ×1