首页 > 技术文章 > Python3.x:关于urllib中urlopen报错问题的解决方案

lizm166 2017-12-24 00:00 原文

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)

 

推荐阅读