Python 2.7 如何使用python通过多个代理服务器发送HTTP或HTTPS请求';s机械化模块?

Python 2.7 如何使用python通过多个代理服务器发送HTTP或HTTPS请求';s机械化模块?,python-2.7,python-3.x,Python 2.7,Python 3.x,我正在尝试使用mechanize模块用python编写代码, 我希望我的http或https请求首先通过几个不同的代理 在请求网页之前。 我怎样才能做到这一点 到目前为止,我已经尝试过: import mechanize import cookielib # Browser br = mechanize.Browser() # Cookie Jar cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) # Browser options br

我正在尝试使用mechanize模块用python编写代码, 我希望我的http或https请求首先通过几个不同的代理 在请求网页之前。 我怎样才能做到这一点

到目前为止,我已经尝试过:

import mechanize
import cookielib

# Browser
br = mechanize.Browser()

# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

# Browser options
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

# User-Agent (this is cheating, ok?)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

# Proxy
br.set_proxies({"http": "myproxy.example.com:3128", "http": "another.proxy.net:3128"})

# Open some site, let's pick a random one, the first that pops in mind:
r = br.open('http://google.com')
html = r.read()

但是,我注意到请求只通过一个代理服务器(始终是词典中的最后一个),因此我的问题是,如何使请求通过这两个代理?

请向我们展示您迄今为止所做的尝试。您好,Yuriy,我刚刚更新了问题。任何帮助都将不胜感激,提前感谢!为了链接代理,您需要使用
CONNECT
方法。这通常是为了限制恶作剧,但是默认配置文件允许大多数端口超过1024个,以及少数端口低于1024个。你好,MattH,谢谢你的回复。连接方法来自哪个模块?