python - matplotlib标题位置 - plt.text用法




如何为python http连接指定经过身份验证的代理? (4)

或者如果你想安装它,那么它总是与urllib2.urlopen一起使用(所以你不需要保持对开启者的引用):

import urllib2
url = 'www.proxyurl.com'
username = 'user'
password = 'pass'
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
# None, with the "WithDefaultRealm" password manager means
# that the user/pass will be used for any realm (where
# there isn't a more specific match).
password_mgr.add_password(None, url, username, password)
auth_handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
print urllib2.urlopen("http://www.example.com/folder/page.html").read()

在python中为http连接指定具有用户名和密码的代理的最佳方法是什么?


用这个:

import requests

proxies = {"http":"http://username:[email protected]_ip:proxy_port"}

r = requests.get("http://www.example.com/", proxies=proxies)

print(r.content)

我认为它比使用urllib简单得多。 我不明白为什么人们如此喜欢使用urllib


这对我有用:

import urllib2

proxy = urllib2.ProxyHandler({'http': 'http://
username:[email protected]:proxyport'})
auth = urllib2.HTTPBasicAuthHandler()
opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
urllib2.install_opener(opener)

conn = urllib2.urlopen('http://python.org')
return_str = conn.read()

这是使用urllib的方法

import urllib.request

# set up authentication info
authinfo = urllib.request.HTTPBasicAuthHandler()
proxy_support = urllib.request.ProxyHandler({"http" : "http://ahad-haam:3128"})

# build a new opener that adds authentication and caching FTP handlers
opener = urllib.request.build_opener(proxy_support, authinfo,
                                     urllib.request.CacheFTPHandler)

# install it
urllib.request.install_opener(opener)

f = urllib.request.urlopen('http://www.python.org/')
"""






proxy