在Python3中如果写以下代码会出现报错,原因就是在Python3中应该把 import urllib=======》import urllib.request
把所有位置都换成带有.request,就可以解决错误了
import urllib
from bs4 import BeautifulSoup
response = urllib.urlopen("http://www.imau.edu.cn")
html = response.read()
data = html.decode('utf-8')
soup = BeautifulSoup(data)
# print soup.findAll('span')
response = urllib.urlopen(“http://www.imau.edu.cn“)
AttributeError: module ‘urllib’ has no attribute ‘urlopen’
例如这个例子改一下:两处改好就OK了
<!—hexoPostRenderEscape:
import urllib.request
from bs4 import BeautifulSoup
response = urllib.request.urlopen("http://www.imau.edu.cn")
html = response.read()
data = html.decode('utf-8')
soup = BeautifulSoup(data)