Python 用lxml提取属性值
我使用lxml库从HTML页面获取属性值 例如:Python 用lxml提取属性值,python,html,xpath,lxml,Python,Html,Xpath,Lxml,我使用lxml库从HTML页面获取属性值 例如: <span class="you-save">Rs. 5000</span> 例如,我想获取属性值 <meta itemprop="price" content="4999.00"> 可以使用属性轴使用@获取属性值 例如: from lxml.etree import fromstring xml = """<some> <nodes> <meta itemprop="pri
<span class="you-save">Rs. 5000</span>
例如,我想获取属性值
<meta itemprop="price" content="4999.00">
可以使用属性轴使用
@
获取属性值
例如:
from lxml.etree import fromstring
xml = """<some>
<nodes>
<meta itemprop="price" content="4999.00"></meta>
</nodes>
</some>"""
doc = fromstring(xml)
print(doc.xpath('//meta[@itemprop="price"]/@content'))
from lxml.etree导入fromstring
xml=”“”
"""
doc=fromstring(xml)
打印(doc.xpath('//meta[@itemprop=“price”]/@content'))
print doc.xpath('//meta[@itemprop="price"]/content::text()')
from lxml.etree import fromstring
xml = """<some>
<nodes>
<meta itemprop="price" content="4999.00"></meta>
</nodes>
</some>"""
doc = fromstring(xml)
print(doc.xpath('//meta[@itemprop="price"]/@content'))