1. I recently learned python and wrote a simple crawler example. I wasted a few hours with the following problems.
# coding=utf-8
import urllib.request
url = "http://www.baidu.com"
data = urllib.request.urlopen(url).read()
data = data.decode('UTF-8')
print(data)
Later I found out that I was using python version 2.7.14
and said that there is no request related method in the source code urllib moudle, but the urlopen method directly
from urlparse import urljoin as basejoin
__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"]
So I changed the code:
# coding=utf-8
import urllib
url = "http://www.baidu.com"
data = urllib.urlopen(url).read()
data = data.decode('UTF-8')
print(data)
solved it right away
As shown in the figure: