import requests
from lxml import etree,html
res = requests.get('https://weixin.sogou.com/weixin?query=%E6%88%BF%E4%BA%A7&_sug_type_=&s_from=input&_sug_=y&type=1&page=1&ie=utf8')
html_info1 = etree.HTML(res)
a = html.tostring(html_info1.xpath('//ul[@class="news-list2"]/li')[0],encoding='utf-8').decode('utf-8')
print(a)
代码如上所述:
可以将用xpath提取的对象再次装换成HTML