【发布时间】:2015-06-06 16:26:43
【问题描述】:
import lxml.html.clean as clean
cleaner = clean.Cleaner(style=True, remove_tags=['div','span',], safe_attrs_only=['href',])
text = cleaner.clean_html('<a href="http://жк-сочи.рф/">link</a>')
print text
打印
<a href="http://%C3%90%C2%B6%C3%90%C2%BA-%C3%91%C2%81%C3%90%C2%BE%C3%91%C2%87%C3%90%C2%B8.%C3%91%C2%80%C3%91%C2%84/">link</a>
如何获得:
<a href="http://жк-сочи.рф/">link</a>
即普通编码中的href?
【问题讨论】:
-
试试 lxml.html.tostring(text , encoding="ascii")
标签: lxml