Python获取网页编码的两种方法——requests、chardet
来源:互联网 发布:java中subtract 编辑:程序博客网 时间:2024/05/22 13:11
运行环境:
Python3.6
、requests2.18.4
方法一:使用requests模块
In[2]: import requestsIn[3]: res = requests.get('http://baidu.com')In[4]: resOut[4]: <Response [200]>In[5]: res.encodingOut[5]: 'ISO-8859-1'
方法二:使用chardet模块
In[2]: import chardetIn[3]: from urllib.request import urlopenIn[4]: url = 'http://www.baidu.com'In[5]: html = urlopen(url).read()In[6]: print(chardet.detect(html)){'encoding': 'utf-8', 'confidence': 0.99, 'language': ''}
阅读全文
0 0
- Python获取网页编码的两种方法——requests、chardet
- python判断字符串编码——使用chardet判断字符串编码的方法
- python字符编码检测——chardet
- python获取网页编码的方法
- python requests module使用cookie的两种方法
- 17.python字符编码检测——chardet
- python中判断文件编码的chardet
- python requests获取网页乱码
- 获取文件编码chardet
- 用chardet判断字符编码的方法
- 用chardet判断字符编码的方法
- 用chardet判断字符编码的方法
- 用chardet判断字符编码的方法
- python3下的编码检测——chardet
- python 2.6/2.7 Requests网页编码问题
- python使用requests爬网页编码问题
- chardet检测爬到的网页的编码
- 获取网页编码的方法
- 沉浸式Dialog&状态栏上面显示View
- 选择结构
- redis系列:将redis启动宿主到Windows服务中
- TensorFlow: Could not load requested Qt binding.
- Oracle 数据库中的内容加密与解密 dbms_crypto
- Python获取网页编码的两种方法——requests、chardet
- 蓝桥杯 算法练习 数的划分
- 工程计算3——解线性方程组的直接法
- 可以这样实例化对象,并初始化对象的属性
- 纯吐槽:少扯些架构,多写些代码,先做到dry
- 服务器有新消息主动推送给客户端浏览器
- (二)spring-boot集成Redis(初级)
- 使用 CMake + VS2017 ( + Python 3) 配置和编译 OpenCV 3.3
- Hibernate中的exists使用