python 常見問題總結


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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM