Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用lxml提取属性值_Python_Html_Xpath_Lxml - Fatal编程技术网

Python 用lxml提取属性值

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

我使用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="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'))