First need to check their python environment is consistent with the package
Appears AttributeError: module 'urllib' has no attribute 'urlopen'
appears AttributeError: module 'urllib' has no attribute 'request'
which errors are introduced into the appropriate packet is related
Package in python3.X environment like this?
import urllib.request #导入的包是url.request
def getHtml(url):
page = urllib.request.urlopen(url) #使用的方式是urllib.request.urlopen()
html = page.read()
return html
html = getHtml("http://www.baidu.com")
print (html)
Package is introduced url.request
method used is the urllib.request.urlopen ()
Package in python2.X environment like this?
import urllib #导入包为urllib
def getHtml(url):
page = urllib.urlopen(url) #使用方式urllib.urlopen
html = page.read()
return html
html = getHtml("http://www.baidu.com")
print html
Url package is introduced
manner using urllib.urlopen ()