Python的机械化代理支持 [英] Python's mechanize proxy support

查看:73
本文介绍了Python的机械化代理支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对python机械化的代理支持有疑问.我正在制作一些Web客户端脚本,我想在我的脚本中插入代理支持功能.

I have a question about python mechanize's proxy support. I'm making some web client script, and I would like to insert proxy support function into my script.

例如,如果我有:

params = urllib.urlencode({'id':id, 'passwd':pw})
rq = mechanize.Request('http://www.example.com', params) 
rs = mechanize.urlopen(rq)

如何在我的机械化脚本中添加代理支持? 每当我打开此www.example.com网站时,我都希望它通过代理.

How can I add proxy support into my mechanize script? Whenever I open this www.example.com website, i would like it to go through the proxy.

推荐答案

您使用mechanize.Request.set_proxy(host,type)(至少从0.1.11开始)

You use mechanize.Request.set_proxy(host, type) (at least as of 0.1.11)

假设运行在localhost:8888的http代理

assuming an http proxy running at localhost:8888

req = mechanize.Request("http://www.google.com")
req.set_proxy("localhost:8888","http")
mechanize.urlopen(req)

应该工作.

这篇关于Python的机械化代理支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆