#The proxy address and port:Proxy_info = {'Host':'proxy.myisp.com', 'Port': 3128 } #We Create a handler for the proxyProxy_support = Urllib2. Proxyhandler ({"http":"http://% (Host) s:% (port) d"%Proxy_info}) #We Create an opener which uses this handler:Opener =Urllib2.build_opener (Proxy_support)#Then we install this opener as the default opener for URLLIB2:Urllib2.install_opener (opener)#Now we can send our HTTP request:HtmlPage = Urllib2.urlopen ("http://sebsauvage.net/"). Read (200000) #if the agent needs to verifyProxy_info = {'Host':'proxy.myisp.com', 'Port': 3128, 'User':'John Doe', 'Pass':'mysecret007'}proxy_support= Urllib2. Proxyhandler ({"http":"http://% (user) s:% (pass) [email protected]% (host) s:% (port) d"%Proxy_info}) Opener=Urllib2.build_opener (Proxy_support) Urllib2.install_opener (opener) HtmlPage= Urllib2.urlopen ("http://sebsauvage.net/"). Read (200000)#The code snippet is from: http://www.sharejs.com/codes/python/226
Python urllib2 using proxies