Having trouble learning Python: import urllib.request ImportError: No module named request

1. I recently learned python and wrote a simple crawler example. I wasted a few hours with the following problems.
write picture description here

# 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:
write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324731350&siteId=291194637