[英]How to get unicode string when extract data in Python?
我正在尝试从越南网站提取文本,该网站的字符集为 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”
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.