1. There are mainly these methods in this module
__all__ = ["urlopen", "URLopener", "FancyURLopener", "urlretrieve", "urlcleanup", "quote", "quote_plus", "unquote", "unquote_plus", "urlencode", "url2pathname", "pathname2url", "splittag", "localhost", "thishost", "ftperrors", "basejoin", "unwrap", "splittype", "splithost", "splituser", "splitpasswd", "splitport", "splitnport", "splitquery", "splitattr", "splitvalue", "getproxies"]
1. holiday :
- urlopen(url, data=None, proxies=None, context=None)
- url global resource locator, data data we want to pass, proxies proxy, context is set to solve the error encountered in 'https', specifically context = ssl._create_unverified_context(). Need to import ssl library.
_urlopener = None # Set _urlopener to None def urlopen(url, data=None, proxies=None, context=None): """Create a file-like object for the specified URL to read from.""" from warnings import warnpy3k warnpy3k("urllib.urlopen() has been removed in Python 3.0 in " "favor of urllib2.urlopen()", stacklevel=2) global _urlopener # There is no global difference, if you do not need to modify the value, you can not add it, but if you need to modify the value, you need to add # First determine whether proxies and context exist, if both exist, pass the parameters to FancyURLopener if proxies is not None or context is not None: opener = FancyURLopener(proxies=proxies, context=context) # It turns out that I have always misunderstood that the initial value of _urlopener is None, and not _urlopener is True. I always thought it was False elif not _urlopener: # Assign the value of FancyURLopener to opener. I always wondered why not assign it directly to _urlopener, but later I found out that this value is to be returned # FancyURLopener This is a derived class that handles exceptions opener = FancyURLopener() _urlopener = opener else: # What is the value of _urlopener? opener = _urlopener # To determine whether data is empty, call the open() method. if data is None: return opener.open(url) else: return opener.open(url, data)
2.urlretrieve