• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > 解决python3 urllib中urlopen报错的问题

解决python3 urllib中urlopen报错的问题

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了urllib2.urlopen,urllib.urlopen,urllib2.urlopen url,urllib没有urlopen,urllib2.urlopen req等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

前言

最近更新了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.) 
</div>

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

正确的使用方法

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

结果示意图:

 

其实也是可以换个utf-8的编码让读取出来的源码更正确的,但这已经是番外的不再提了。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。

</div>

您可能想查找下面的文章:

  • 解决python3 urllib中urlopen报错的问题
  • 解决python3 urllib中urlopen报错的问题
  • Python使用urllib模块的urlopen超时问题解决方法
  • Python urllib模块urlopen()与urlretrieve()详解

相关文章

  • python计算程序开始到程序结束的运行时间和程序运行的CPU时间
  • 零基础学Python(一)Python环境安装
  • Python中Collection的使用小技巧
  • pygame播放音乐的方法
  • Python 多线程实例详解
  • python用模块zlib压缩与解压字符串和文件的方法
  • python脚本设置超时机制系统时间的方法
  • 跟老齐学Python之有容乃大的list(1)
  • python实现爬虫统计学校BBS男女比例(一)
  • Python环境下安装使用异步任务队列包Celery的基础教程

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 用Python写飞机大战游戏之pygame入门(4):获取鼠标的位置及运动
    • python登录QQ邮箱发信的实现代码
    • Python Matplotlib库入门指南
    • Python import用法以及与from...import的区别
    • python使用7z解压软件备份文件脚本分享
    • python实现博客文章爬虫示例
    • paramiko模块安装和使用(远程登录服务器)
    • python让图片按照exif信息里的创建时间进行排序的方法
    • Python采用socket模拟TCP通讯的实现方法
    • python实现的希尔排序算法实例

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有