以下是我的一些XML代码示例:
<VAST version="2.0">
<Ad id="602678">
<InLine>
<AdSystem>Acudeo Compatible</AdSystem>
<AdTitle>NonLinear Test Campaign 1</AdTitle>
<Description>NonLinear Test Campaign 1</Description>
<Creatives>
<Creative AdID="602678-NonLinear">
</Creative>
</Creatives>
</InLine>
</Ad>
</VAST>
这个XML是在网上提供的,所以我点击一个特定的URL来获取这些数据。但是,在某些情况下,不会返回任何内容,因此我正在寻找一种方法来验证“Creatives”节点是否存在于任何给定时间返回的内容中。我尝试过BeautifulSoup,但运气不好,但我认为它更适合于HTML而不是XML。非常感谢您的帮助,谢谢。你知道吗
假设您从如下URL检索XML:
然后您只需构建一个简单的函数,它将根据所需的XML标记是否存在返回
True
/False
:例如,让我们以following URL为例:
以上内容将返回以下形式的XML:
如果我们检查一下标签:
所以,如果我要这么做,我会这样写:
也可以使用XPath
相关问题 更多 >
编程相关推荐