UnicodeEncodeError: 'ascii' codec can't encode characters
将网页get到之后输入文本出现UnicodeEncodeError: 'ascii' codec can't encode characters错误
f = open('re.txt', 'w')
url = "http://www.baidu.com"
r = requests.get(url)
r.raise_for_status()
r.encoding = r.apparent_encodingprint(r.text)
f.write(r_text)
f.close()
解决办法是
r_text = r.text.encode('UTF-8')
加入这一行
UnicodeEncodeError: 'ascii' codec can't encode characters的更多相关文章
- Python编码问题:UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(12
今天安装了PyScripter编辑器,刚要写代码,突然就出现异常: <span style="font-size:14px;color:#ff0000;">>&g ...
- python+selenium运行报错UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
使用python+selenium运行自动化脚本时,打印某一段文字出现UnicodeEncodeError: 'ascii' codec can't encode characters in posi ...
- Pip 安装 出现UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-5: ordinal not in
在Python 环境下,使用PiP 命令安装时,报错提示: UnicodeEncodeError: 'ascii' codec can't encode characters in position ...
- 解决UnicodeEncodeError: 'ascii' codec can't encode characters in position 问题(转)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 8-11: ordinal not in range(128 ...
- UnicodeEncodeError: 'ascii' codec can't encode characters in position 14-15: ordinal not in range(128)
python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报类似这样的错误. UnicodeEncodeError: 'ascii' codec can't ...
- 解决Python2.7的UnicodeEncodeError:'ascii' codec can't encode characters in position 0-78: ordinal not in range(128)异常错误
解决Python2.7的UnicodeEncodeError: 'ascii' codec can't encode异常错误 大家都知道,在使用python进行网络爬虫时,最头疼的就是转码问题,下面是 ...
- 【转】Python3—UnicodeEncodeError 'ascii' codec can't encode characters in position 0-1
转自:https://blog.csdn.net/AckClinkz/article/details/78538462 环境 >>> import sys >>> ...
- pip install 安装出现问题:UnicodeEncodeError: 'ascii' codec can't encode characters in position XX的解决办法
pip install 安装出现问题:UnicodeEncodeError: 'ascii' codec can't encode characters in position XX的解决办法 转自c ...
- UnicodeEncodeError: 'ascii' codec can't encode characters in position
UnicodeEncodeError: 'ascii' codec can't encode characters in position python运行时出现这个错误,解决方法如下: 加入如下语句 ...
- UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-25: ordinal not in range(128)
python报错:UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-25: ordinal not in ...
随机推荐
- MySQL实例多库某张表数据文件损坏导致xxx库无法访问故障恢复
一.问题发现 命令行进入数据库实例手动给某张表进行alter操作,发现如下报错. mysql> use xx_xxx; No connection. Trying to reconnect... ...
- insmod: can't insert 'xxx.ko': unknown symbol in module, or unknown parameter
手动加载内核模块时候,报如下错误信息 insmod: can't insert 'xxx.ko': unknown symbol in module, or unknown parameter 问题原 ...
- GOLANG利用断言调用结构体内特有的方法-
package main import( "fmt" _"sort" _"math/rand" ) //多态的特征是通过接口来实现的 //多 ...
- CentOS下更改yum源
centos下下载工具为yum,对应的源在/etc/yum.repos.d/CentOS-Base.repo文件下,修改其URI中前面的网络地址即可
- SQL查询CASE遇上NULL怎么办?
原SQL: case userName when null THEN '空' else '有值' end, 这种写法不好使: 换一种:case when userName is null THEN ...
- kvm批量创建虚拟主机
1.首先你的提前创建一个kvm虚拟机主机,才能批量复制创建 批量复制已经安装好的系统盘 `;.img centos7-$i.img && echo $i ;done 批量复制已经安装好 ...
- C#中使用ListView动态添加数据不闪烁(网上方法会出问题)
最近需要使用做一个动态行显示,所以就用到了ListView控件,在网上也查到了关于动态添加不闪烁的方式都是如下: 首先,自定义一个类ListViewNF,继承自 System.Windows.Form ...
- [Sping Boot] Build a REST CRUD API with Hibernate
pom.xml: <dependencies> <dependency> <groupId>org.springframework.boot</groupId ...
- P2502 [HAOI2006]旅行 最小生成树
思路:枚举边集,最小生成树 提交:1次 题解:枚举最长边,添加较小边. #include<cstdio> #include<iostream> #include<algo ...
- Luogu P1092 虫食算 爆搜
心路历程:震惊,我竟然得了$90$分!!...康康数据...奥..(忽然有了邪恶的卡数据的想法) 于是把$for(int \space i=0;i<n;++i)$改成了$for(int \spa ...