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 ...
随机推荐
- How to export Overload functions from DLL?
Library that exports functions library liba; procedure F(X: Integer); stdcall; overload; begin end; ...
- Physical Education Lessons CodeForces - 915E (动态开点线段树)
Physical Education Lessons CodeForces - 915E This year Alex has finished school, and now he is a fir ...
- 使用php实现javascript的escape和unescape函数
javascript有编码函数escape()和对应的解码函数unescape(),而php中只有个urlencode和urldecode,这个编码和解码函数对encodeURI和encodeURIC ...
- Python单例模式(Singleton)的N种实现
很多初学者喜欢用全局变量,因为这比函数的参数传来传去更容易让人理解.确实在很多场景下用全局变量很方便.不过如果代码规模增大,并且有多个文件的时候,全局变量就会变得比较混乱.你可能不知道在哪个文件中定义 ...
- 从mysql8.0读取数据并形成pandas dataframe类型数据,精确定位行列式中的元素,并读取
from pandas import * import pandas as pd from sqlalchemy import create_engine engine = create_engine ...
- String替换占位符
/** * 依次替换占位符 * 例如: 姓名:{s},电话:{s},邮箱:{s} --> 姓名:小张,电话:18800000001,邮箱:abc@123.com * pattern = &quo ...
- JS栈内存与堆内存
㈠JavaScript变量 ⒈分类 ⑴JavaScript中的变量分为基本类型和引用类型. ⑵基本类型就是保存在栈内存中的简单数据段. ⑶引用类型指的是那些保存在堆内存中的对象. ⒉基本类型 基本类 ...
- Luogu P1198 [JSOI2008]最大数 单调队列/ST表
开一个单调队列,下标递增,值递减. 然后在上面二分最大数. 如果加上并查集可以做到接近线性. 还有一种是插入一个数然后,从后向前更新ST表. #include<cstdio> #inclu ...
- JSONOjbect,对各种属性的处理
import com.alibaba.fastjson.JSONObject; public class JsonTest { public static void main(String[] arg ...
- mac使用brew安装mysql报RROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
使用mac安装mysql安装完后运行 mysql -uroot -p 报了 ERROR 2002 (HY000): Can't connect to local MySQL server throug ...