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

python 获取网页编码方式实现代码

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

lqh 通过本文主要向大家介绍了python设置编码方式,python 编码方式,python url编码,python 汉字编码,python 编码等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

python 获取网页编码方式实现代码

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">
  </span><span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">
python开发,自动化获取网页编码方式用到了chardet库,字符集检测,这个类在python2.7中没有,需要在官网上下载。
这里我下载好了chardet-2.3.0.tar.gz压缩包文件,只需要将压缩包文件解压后的chardet文件放到python安装包下的
python27/lib/site-packages/下,就可以了。</span> 
</div>

 然后import chardet

下面写了一个自动化检测的函数供检测Url连接,然后返回网页url的编码方式。

import chardet #字符集检测 
import urllib 
 
url="http://www.jd.com" 
 
 
def automatic_detect(url): 
  content=urllib.urlopen(url).read() 
  result=chardet.detect(content) 
 
  encoding=result['encoding'] 
 
  return encoding 
 
urls=['http://www.baidu.com','http://www.163.com','http://dangdang.com'] 
for url in urls: 
  print url,automatic_detect(url) 

</div>

上面用到了chardet类的detect方法,返回字典,然后取出编码方式encoding

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

</div>

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

  • python 获取网页编码方式实现代码

相关文章

  • Python yield使用方法示例
  • python文件与目录操作实例详解
  • Python网络爬虫出现乱码问题的解决方法
  • python解决方案:WindowsError: [Error 2]
  • python3中dict(字典)的使用方法示例
  • Python实现的tab文件操作类分享
  • win系统下为Python3.5安装flask-mongoengine 库
  • Python中的数据对象持久化存储模块pickle的使用示例
  • python模拟登录百度贴吧(百度贴吧登录)实例
  • 浅谈Python中用datetime包进行对时间的一些操作

文章分类

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

最近更新的内容

    • Python中实现对Timestamp和Datetime及UTC时间之间的转换
    • 在Django中使用Sitemap的方法讲解
    • 深入理解NumPy简明教程---数组1
    • Python 'takes exactly 1 argument (2 given)' Python error
    • python使用正则表达式提取网页URL的方法
    • 在Windows系统上搭建Nginx+Python+MySQL环境的教程
    • python清除指定目录内所有文件中script的方法
    • python使用psutil模块获取系统状态
    • Python实现的RSS阅读器实例
    • python实现倒计时的示例

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

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