[英]Decoding string from html webpage with lxml
the input string is like: 输入字符串如下:
“ hello world ” with double quotes
i use 我用
Htmlpage=parse(htmlwebpage) from lxml
the output string i get is in the form: 我得到的输出字符串的形式为:
' â\x80\x9c hello world \xa0 '
instead of 代替
'"Hello world"'
i am on windows Thanks 我在窗户上谢谢
I finally found some solutions: 我终于找到了一些解决方案:
i found the webpage format using: 我使用以下方法找到了网页格式:
webpage.headers.get_content_charset()
i specified the parser format in the parse function like: 我在解析函数中指定了解析器格式,例如:
EncodeFormat=lxml.html.HTMLParser(encoding='utf-8')
then 然后
Htmlpage=parse(htmlwebpage,EncodeFormat)
i still had an \\xa0 in the string i removed with: 我删除的字符串中仍然有一个\\ xa0:
string.replace('\xa0','')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.