在 Python 中通过 urllib2 使用 cookie 和代理
我正在使用 urllib2 与网络服务器交互。对于我需要解决的具体问题,我需要通过代理对流量进行隧道传输。我设法用 urllib2 'ProxyHandler' 做到了这一点。
我还需要接受和发送cookie。我设法使用 urllib2 'cookielib.LWPCookieJar()' 来做到这一点。
问题是,虽然他们单独工作,但他们不能“一起”工作。我用“urllib2.install_opener(opener)”添加的最后一个开启器是可以工作的。
是否可以有两个活跃的“开启者”?或者用另一种方法来解决这个问题?
I'm using urllib2 to interact with a webserver. For the specific problem I need to solve, I need to tunnel the traffic through a proxy. I managed to do that with a urllib2 'ProxyHandler'.
I also need to accept and send cookies. I managed to do that with a urllib2 'cookielib.LWPCookieJar()'.
The problem is that while they work individually, they don't work 'together'. The last opener that I add with 'urllib2.install_opener(opener)' is the one that will work.
Is is possible to have two active 'openers'? Or another way to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将代理处理程序和 cookie 处理器组合在一个 opener 中:
Combine proxy handler and cookie processor in a single opener: