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.xxx.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)
出处:www.l1mn.com
原文标题:python 常见问题总结
原文地址:https://www.l1mn.com/p/a0jbf3.html
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
Copyright © L1MN.COM 联系方式:l1mnfw@163.com