使用 XPath 抓取不包含某个子元素的元素
Use XPath to scrape elements which do not contain a certain child element
对于抓取工具,我希望获得页面上所有元素的列表,其中不包含某个子元素。 DOM 看起来像这样
<scrape>
<div id='123'>
<span>test</span>
</div>
</scrape>
<scrape>
<div id='1234'>
<span>test</span>
</div>
</scrape>
<scrape>
<div id='12345'>
<span>test</span>
<span>don't include</span>
</div>
</scrape>
我需要做的是,我的列表需要包含所有 scrape 元素,这些元素不包含 span with text don't include。
有什么想法吗?
谢谢!
这应该有效
//scrape[not(.//span[text()='don't include'])]
直译:
标签名称为 scrape
而不是 的元素内部(子元素)标签名称为 span
且 text
的值为 don't include
对于抓取工具,我希望获得页面上所有元素的列表,其中不包含某个子元素。 DOM 看起来像这样
<scrape>
<div id='123'>
<span>test</span>
</div>
</scrape>
<scrape>
<div id='1234'>
<span>test</span>
</div>
</scrape>
<scrape>
<div id='12345'>
<span>test</span>
<span>don't include</span>
</div>
</scrape>
我需要做的是,我的列表需要包含所有 scrape 元素,这些元素不包含 span with text don't include。
有什么想法吗?
谢谢!
这应该有效
//scrape[not(.//span[text()='don't include'])]
直译:
标签名称为 scrape
而不是 的元素内部(子元素)标签名称为 span
且 text
的值为 don't include