我正在尝试从越南网站提取文本,该网站的字符集为 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ơ đậu phộng thơm bùi”
谢谢。
最佳答案
关于python - 在Python中提取数据时如何获取unicode字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32675046/