如何使用带有 url 和基本身份验证凭据的 scrapy shell? [英] How can use scrapy shell with url and basic auth credentials?
本文介绍了如何使用带有 url 和基本身份验证凭据的 scrapy shell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 scrapy shell
并测试需要基本身份验证凭据的 url 的响应数据.我试图检查scrapy shell文档,但在那里找不到它.
I want to use scrapy shell
and test response data for url which requires basic auth credentials. I tried to check scrapy shell documentation but I couldn't find it there.
我尝试使用 scrapy shell 'http://user:pwd@abc.com'
但它没有用.有谁知道我如何实现它?
I tried with scrapy shell 'http://user:pwd@abc.com'
but it didn't work.
Does anybody know how I can achieve it?
推荐答案
如果你只想使用 shell,你可以这样做:
if you want to use only the shell, you could do something like this:
$ scrapy shell
在外壳内:
>> from w3lib.http import basic_auth_header
>> from scrapy import Request
>> auth = basic_auth_header(your_user, your_password)
>> req = Request(url="http://example.com", headers={'Authorization': auth})
>> fetch(req)
as fetch
使用当前请求来更新 shell 会话.
as fetch
uses the current request to update the shell session.
这篇关于如何使用带有 url 和基本身份验证凭据的 scrapy shell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文