我有两个不同的网页,我想使用XPath提取一些值。什么请求可以从第一页提取2386028,同时可以从第二页提取4019606?我需要一个可以普遍提取这些价值观的请求。
首页片段:
<ul class="g-ul b-properties">
<li class="b-properties__header">General</li>
<li class="b-properties__item">
<span class="b-properties__label">
<span>VendorCode</span>
</span>
<span class="b-properties__value">2386028</span>
</li>
<li class="b-properties__item">...</li>
<li class="b-properties__item">...</li>
<li class="b-properties__item">...</li>
第二页片段:
<div class="b-properties-holder" id="tab_3">
<ul class="g-ul b-properties">
<li class="b-properties__header">General</li>
<li class="b-properties__item">
<span class="b-properties__label">
<span>Trademark</span>
</span>
<span class="b-properties__value">
<a class="link b-properties-link" href="/trademark/moist-diane/?sort=-date&currency=USD">Moist Diane</a>
</span>
</li>
<li class="b-properties__item">
<span class="b-properties__label">
<span>VendorCode</span>
</span>
<span class="b-properties__value">4019606</span>
</li>
<li class="b-properties__item">...</li>
<li class="b-properties__item">...</li>
您可以选择<li>
元素,该元素具有包含值为VendorCode
的<span>
的<span class="b-properties__label">
元素,然后在该<li>
元素下获得<span class="b-properties__value">
的值。
例如:
//li[span[@class="b-properties__label"]/span="VendorCode"]/span[@class="b-properties__value"]/text()
或者,您可以选择<span class="b-properties__label">
元素,该元素具有值为VendorCode
的<span>
,并获取其以下同级元素。
//span[@class="b-properties__label" and span="VendorCode"]/following-sibling::span/text()