Python3.x:关于urllib中urlopen报错问题的解决方案

Python3.x:关于urllib中urlopen报错问题的解决方案

调用:urllib.urlopen(url)

报错:AttributeError: 'module' object has no attribute 'urlopen'

原因:

1,官方文档的解释:

      

官方3.0版本已经把urllib2,urlparse等五个模块都并入了urllib中,也就是整合了。

2,正确的使用方法:

import urllib.request
url = "http://www.baidu.com"
get = urllib.request.urlopen(url).read()
print(get)

 

posted @ 2017-12-24 00:00  整合侠  阅读(3082)  评论(0编辑  收藏  举报