【发布时间】:2015-10-18 14:42:06
【问题描述】:
我正在使用Html2Text 将 html 代码转换为文本。
效果很好,但我在互联网上找不到很多示例或文档。
我是这样读取用户名的:
text_to_gain = hxs.xpath('//div[contains(@id,"yq-question-detail-profile-img")]/a/img/@alt').extract()
if text_to_gain:
h = html2text.HTML2Text()
h.ignore_links = True
item['author'] = h.handle(text_to_gain[0])
else:
item['author'] = "anonymous"
但我的输出是这样的:
u'Duncan\n\n'
当我阅读长文本或消息时,使用 \n 很有用,但对于单个字符串或某些我只想保留名称。
'Duncan'
【问题讨论】:
标签: python string python-2.7 selenium