我试图从一个越南网站上提取文本,这个字符集是utf-8。但是,我得到的文本总是Ascii格式的,我无法找到将它们转换为unicode的方法,也无法在网站上获得准确的文本。结果,我无法按预期将它们保存到文件中。
我知道这是Python中unicode非常流行的问题,但我仍然希望有人能帮助我解决这个问题。谢谢。
我的代码:
import requests, re, io
import simplejson as json
from lxml import html, etree
base = "http://www.amthuc365.vn/cong-thuc/"
page = requests.get(base + "trang-" + str(1) + ".html")
pageTree = html.fromstring(page.text)
links = pageTree.xpath('//ul[contains(@class, "mt30")]/li/a/@href')
names = pageTree.xpath('//h3[@class="title"]/a/text()')
for name in names[:1]:
print name
# Là m bánh oreo nhân bÆ¡ Äáºu phá»ng thÆ¡m bùi
但我需要的是“Lám bánh oreo nh’n bơ273;ậu phộng thơm bùI”
谢谢。在
只要从
page.text
切换到page.content
就可以了。在解释here。在
另请参见:
相关问题 更多 >
编程相关推荐