gpt4 book ai didi

Python & lxml/xpath : Parsing XML

转载 作者:数据小太阳 更新时间:2023-10-29 02:22:17 27 4
gpt4 key购买 nike

我需要从此链接的 FLVPath 中获取值:http://www.testpage.com/v2/videoConfigXmlCode.php?pg=video_29746_no_0_extsite

from lxml import html

sub_r = requests.get("http://www.testpage.co/v2/videoConfigXmlCode.php?pg=video_%s_no_0_extsite" % list[6])
sub_root = lxml.html.fromstring(sub_r.content)

for sub_data in sub_root.xpath('//PLAYER_SETTINGS[@Name="FLVPath"]/@Value'):
print sub_data.text

但是没有返回数据

最佳答案

您正在使用 lxml.html 来解析文档,这会导致 lxml 将所有元素和属性名称小写(因为这在 html 中无关紧要),这意味着您必须使用:

sub_root.xpath('//player_settings[@name="FLVPath"]/@value')

或者当您无论如何都在解析 xml 文件时,您可以使用 lxml.etree

关于Python & lxml/xpath : Parsing XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13791640/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com