没有合适的资源?快使用搜索试试~ 我知道了~
首页解决python3 urllib中urlopen报错的问题
前言 最近更新了Python版本,准备写个爬虫,意外的发现urllib库中属性不存在urlopen,于是各种google,然后总结一下给出解决方案 问题的出现 AttributeError: ‘module’ object has no attribute ‘urlopen’ 问题的解决途径 我们先来看下官方文档的解释: a new urllib package was created. It consists of code from urllib, urllib2, urlparse, and robotparser. The old modules have all be
资源详情
资源评论
资源推荐

解决解决python3 urllib中中urlopen报错的问题报错的问题
前言前言
最近更新了Python版本,准备写个爬虫,意外的发现urllib库中属性不存在urlopen,于是各种google,然后总结一下给出解决
方案
问题的出现问题的出现
AttributeError: ‘module’ object has no attribute ‘urlopen’
问题的解决途径问题的解决途径
我们先来看下官方文档的解释:我们先来看下官方文档的解释:
a new urllib package was created. It consists of code from
urllib, urllib2, urlparse, and robotparser. The old
modules have all been removed. The new package has five submodules:
urllib.parse, urllib.request, urllib.response,
urllib.error, and urllib.robotparser. The
urllib.request.urlopen() function uses the url opener from
urllib2. (Note that the unittests have not been renamed for the
beta, but they will be renamed in the future.)
也就是说官方3.0版本已经把urllib2,urlparse等五个模块都并入了urllib中,也就是整合了。
正确的使用方法正确的使用方法
import urllib.request
url="http://www.baidu.com"
get=urllib.request.urlopen(url).read()
print(get)
结果示意图:结果示意图:


















安全验证
文档复制为VIP权益,开通VIP直接复制

评论10