我想从HTML解析schemadata并使用XPATH安排数据。
*模式数据信息
<div itemscope itemtype="http://www.schema.org/Product">
<div itemscope itemtype="http://www.schema.org/Person">
<span itemprop="birthday" datetime="2009-05-10">May 10th 2009</span>
</div>
<div itemprop="name"> Product name </div>
<div itemprop="offers" itemscope itemtype="https://schema.org/Offer">
<span itemprop="price" content="500.00"> USD 500 </span>
</div>
</div>
所需结果如下: 为了解析类别,产品和人员,我使用了以下代码:
var category = $x("//*[@itemtype and not(@itemprop)]");
//category[0] = <div itemscope itemtype="http://www.schema.org/Product">
//category[1] = <div itemscope itemtype="http://www.schema.org/Person">
对于category[0]
,在解析具有属性“ itemprop”的元素之前,我必须排除category[1]
,因为category[0]
包括category[1]
。
我编写了这段代码,但是我无法将多个条件组合为一个。
var category = $x("//*[@itemtype and not(@itemprop)]");
-----------------------------------------------------------------------------
1. var product = $x("//*[@itemprop and not(@itemtype)]",category[0]);
2.Under category[0] nodes,I would like to exclude these nodes which met this condition,[contains(@itemtype,'schema.org/') and not(@itemprop)]/descendant-or-self::*
-----------------------------------------------------------------------------
如何在category[1]
中排除category[0]
节点及其子节点,以获得所需结果?我认为我必须将这些1和2条件合并为一个,但是我不知道。请阐明这件事。
非常感谢,感恩节快乐:)