0
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?
try lxml.html.tostring(text,encoding =「ascii」) –