我试图用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
我将在服务器上运行这个程序(当然,当前部分只是一个快速测试)
s=soup.prettify().encode('utf8')
使其显式为UTF-8。在在shell中设置
PYTHONIOENCODING=utf8
,然后print(soup.prettify())
应该隐式使用指定的编码。在相关问题 更多 >
编程相关推荐