我想使用scrapy shell并测试需要基本身份验证凭据的URL的响应数据。我试图检查草率的shell文档,但在那儿找不到它。

我尝试了scrapy shell 'http://user:pwd@abc.com',但是没有用。
有人知道我能做到吗?

请您参考如下方法:

如果您只想使用 shell ,则可以执行以下操作:

$ scrapy shell 

并在 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) 

因为 fetch使用当前请求来更新Shell session 。


评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!