Python : AttributeError: 'module' object has no attribute 'urlopen'

PYthon : AttributeError: ‘module’ object has no attribute ‘urlopen’

如何解决AttributeError:‘module’ object has no attribute ‘urlopen’——python.

前言

最近更新了Python版本,准备写个爬虫,意外的发现urllib库中属性不存在urlopen,于是各种google,然后总结一下给出解决方案

问题的出现:
在这里插入图片描述
问题的解决途径

我们先来看下官方文档的解释:
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)

AttributeError: ‘module’ object has no attribute 'urlopen’问题的解决途径

下次遇到这个问题的时候,可以参考,2019.08.22

参考link:https://www.jb51.net/article/109508.htm

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 当出现"AttributeError: 'module' object has no attribute 'xxx'"的错误时,通常是因为模块中没有名为'xxx'的属性。这可能是由于.pyc文件存在问题导致的。\[1\]解决方法是更新.pyc文件。另外,当执行Python代码时出现"AttributeError: 'module' object has no attribute 'urlopen'"的错误时,也可以尝试更新相关的.pyc文件来解决问题。\[2\]至于你提到的"AttributeError: 'module' object has no attribute 'ticks'"错误,根据提供的信息,无法确定具体的原因。请提供更多的上下文信息,以便我能够给出更准确的答案。 #### 引用[.reference_title] - *1* *2* [Python脚本报错AttributeError: ‘moduleobject has no attribute’xxx’解决方法](https://blog.csdn.net/u011950993/article/details/51454645)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [AttributeError: 'module' object has no attribute 的解决方法](https://blog.csdn.net/Eddy_zheng/article/details/47394369)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值