requests 获取文本标签 HTML 内容

from lxml import etree
import requests
url = "https://blog.csdn.net/qcyfred/article/details/79284263"
res = requests.get(url=url)
a = etree.HTML(res.content.decode("utf-8"))
b  = a.xpath('//h1')[0]
content = etree.tostring(b, pretty_print=True, method='html', encoding='utf-8').decode("utf-8")  # 转为字符串
print(content)

参考链接: https://blog.csdn.net/diyiday/article/details/81058942

猜你喜欢

转载自blog.csdn.net/chang995196962/article/details/88246141