[英]How to parse HTML using the lxml.html library
Use xpath to find the meta
tag by name
attribute and get the value of content
attribute: 使用xpath通过name
属性查找meta
标记并获取content
属性的值:
from lxml.html import fromstring
html_data = """ <meta content="auth" name="param" />
<meta content="I_WANT_THIS" name="token" />"""
tree = fromstring(html_data)
print tree.xpath('//meta[@name="token"]/@content')
prints: 打印:
['I_WANT_THIS']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.