python No module named 'urlparse'
1、ModuleNotFoundError: No module named 'urllib2'
在python3.x版本中,urllib和urllib2包集合成在一個包了
import urllib2
response = urllib2.urlopen(request)
改為
import urllib.request
response = urllib.request.urlopen("http://www.fyunw.com")
2、ModuleNotFoundError: No module named 'urlparse'
3.0版本中已經將urllib2、urlparse、和robotparser併入了urllib中,並且修改urllib模組,其中包含5個子模組,即是help()中看到的那五個名字。
urllib.error: ContentTooShortError; HTTPError; URLError
urllib.parse: parseqs; parseqsl; quote; quotefrombytes; quote_plus; unquote unquoteplus; unquoteto_bytes; urldefrag; urlencode; urljoin; urlparse; urlsplit; urlunparse; urlunsplit
urllib.request: AbstractBasicAuthHandler; AbstractDigestAuthHandler; BaseHandler; CatheFTPHandler; FTPHandler; FancyURLopener; FileHandler; HTTPBasicAuthHandler; HTTPCookieProcessor; HTTPDefaultErrorHandler; HTTPDigestAuthHandler; HTTPErrorProcessorl; HTTPHandler; HTTPPasswordMgr; HTTPPasswordMgrWithDefaultRealm; HTTPRedirectHandler; HTTPSHandler;OpenerDirector;ProxyBasicAuthHandler ProxyDigestAuthHandler; ProxyHandler; Request; URLopener; UnknowHandler; buildopener; getproxies; installopener; pathname2url; url2pathname; urlcleanup; urlopen; urlretrieve;
urllib.response: addbase; addclosehook; addinfo; addinfourl;
urllib.robotparser: RobotFileParser
import urlparse
my_url = urlparse.urlparse(url)
改為
import urllib
my_url = urllib.urlparse(url)