我试图从一个splash请求中获取cookies,但是我一直得到一个错误。在
以下是我使用的代码:
class P2PEye(scrapy.Spider):
name = 'p2peyeSpider'
allowed_domains = ['p2peye.com']
start_urls = ['https://www.p2peye.com/platform/h9/']
def start_requests(self):
script = '''
function main(splash)
local url = splash.args.url
assert(splash:go(url))
assert(splash:wait(0.5))
return {
cookies = splash:get_cookies(),
}
end
'''
for url in self.start_urls:
yield SplashRequest(url, callback=self.parse, endpoint='render.html',args={'wait': 1, 'lua_source': script})
def parse(self, response):
print(response.request.headers.getlist('Set-Cookie'))
print(response.cookiejar)
这是我的settings.py
response.request.headers.getlist('Set-Cookie')
的结果是[]
,
并且response.cookiejar
得到了一个错误:AttributeError: 'SplashTextResponse' object has no attribute 'cookiejar'
。
那么我怎样才能在不引起错误的情况下得到cookies呢?在
要访问
response.cookiejar
,您需要返回SplashJsonResponse
尝试在Lua脚本中返回额外的字段:
相关问题 更多 >
编程相关推荐