Python最基本方法抓取网站数据时,报错:ModuleNotFoundError:No module named 'urllib2' 。
错误原因:Python版本
Python3版本,代码是Python2的格式

解决办法:
urllib.request代替urllib2
response.read()改为 resp.read()
print html 加括号
Python3版本下,正确抓取代码:
>>> import urllib.request
>>> resp=urllib.request.urlopen('http://www.baidu.com')
>>> html=resp.read()
>>> print(html)
网友评论