如何使用PYTHONIOENCODING环境变量通过unicode解释问题

2024-09-28 21:19:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Python运行一个非常短的脚本

from bs4 import BeautifulSoup
import urllib.request




html = urllib.request.urlopen("http://dictionary.reference.com/browse/word?s=t").read().strip()
dhtml = str(html, "utf-8").strip()
soup = BeautifulSoup(dhtml.strip(), "html.parser")

我早些时候问了一个类似的问题,这个问题是根据塞巴斯蒂安对他的回答所作的一个值得尊敬的评论而提出的。Python program is running in IDLE but not in command line

有没有办法在Github的Atom或Sublime text2中设置PythonIOEncoding来自动将soup.prettify()编码为utf-8

我将在服务器上运行这个程序(当然,当前部分只是一个快速测试)


Tags: infromimport脚本requesthtmlurllibutf