python 3.X版本是不需要安装:urllib2包的,urllib和urllib2包集合成在一个包了
那现在问题是:
在python3.x版本中,如何使用:urllib2.urlopen()?
答:
import urllib.request
resp=urllib.request.urlopen(http://www.baidu.com)
来源:https://www.cnblogs.com/zdlfb/p/6130724.html
附:
Python2 urllib2 与 Python3 urllib.request API对照
urllib2.urlopen() | urllib.request.urlopen() |
urllib2.install_opener() | urllib.request.install_opener() |
urllib2.build_opener() | urllib.request.build_opener() |
urllib2.URLError | urllib.error.URLError |
urllib2.HTTPError | urllib.error.HTTPError |
urllib2.Request | urllib.request.Request |
urllib2.OpenerDirector | urllib.request.OpenerDirector |
urllib2.BaseHandler | urllib.request.BaseHandler |
urllib2.HTTPDefaultErrorHandler | urllib.request.HTTPDefaultErrorHandler |
urllib2.HTTPRedirectHandler | urllib.request.HTTPRedirectHandler |
urllib2.HTTPCookieProcessor | urllib.request.HTTPCookieProcessor |
urllib2.ProxyHandler | urllib.request.ProxyHandler |
urllib2.HTTPPasswordMgr | urllib.request.HTTPPasswordMgr |
urllib2.HTTPPasswordMgrWithDefaultRealm | urllib.request.HTTPPasswordMgrWithDefaultRealm |
urllib2.AbstractBasicAuthHandler | urllib.request.AbstractBasicAuthHandler |
urllib2.HTTPBasicAuthHandler | urllib.request.HTTPBasicAuthHandler |
urllib2.ProxyBasicAuthHandler | urllib.request.ProxyBasicAuthHandler |
urllib2.AbstractDigestAuthHandler | urllib.request.AbstractDigestAuthHandler |
urllib2.HTTPDigestAuthHandler | urllib.request.HTTPDigestAuthHandler |
urllib2.ProxyDigestAuthHandler | urllib.request.ProxyDigestAuthHandler |
urllib2.HTTPHandler | urllib.request.HTTPHandler |
urllib2.HTTPSHandler | urllib.request.HTTPSHandler |
urllib2.FileHandler | urllib.request.FileHandler |
urllib2.FTPHandler | urllib.request.FTPHandler |
urllib2.CacheFTPHandler | urllib.request.CacheFTPHandler |
urllib2.UnknownHandler | urllib.request.UnknownHandler |