我有这样的html结构..
<div id="divid">
<ul id="ulid">
<li style="margin-left: 8px">
<strong>books</strong>
</li>
<li style="margin-left: 6px">
<a hre="">
<span id="spanid">first line</span></a>
</li>
<li style="margin-left: 6px">
<a hre="">
<span id="spanid">2nd line</span></a>
</li>
</ul>
</div>
我正在解析这个html部分并使用xpath查询
$xpath->query('//div[@id="divid"]/ul[@id="ulid"]/li/a');
我想要的输出是
第一行第二行
据我了解,如果第一个“li”标签中没有“strong”标签,我的xpath查询就可以了。
我工作的原始代码是......
<ul data-typeid="n" id="ref_1000">
<li style="margin-left: -18px;">
<a href="/s/ref=sr_ex_n_0?rh=i%3Aaps%2Ck%3Ahow+to+grow+tomatoes&sort=salesrank&keywords=how+to+grow+tomatoes&ie=UTF8&qid=1327692925">‹ <span class="expand">Any Department</span></a>
</li>
<li style="margin-left: 8px;">
<strong>Books</strong>
</li>
<li style="margin-left: 6px;">
<a href="/s/ref=sr_nr_n_0?rh=k%3Ahow+to+grow+tomatoes%2Cn%3A283155%2Cp_n_feature_browse-bin%3A618073011%2Cn%3A%211000%2Cn%3A48&bbn=1000&sort=salesrank&keywords=how+to+grow+tomatoes&ie=UTF8&qid=1327692925&rnid=1000">
<span class="refinementLink">Crafts, Hobbies & Home</span><span class="narrowValue"> (19)</span>
</a>
</li>
<li style="margin-left: 6px;">
<a href="/s/ref=sr_nr_n_1?rh=k%3Ahow+to+grow+tomatoes%2Cn%3A283155%2Cp_n_feature_browse-bin%3A618073011%2Cn%3A%211000%2Cn%3A10&bbn=1000&sort=salesrank&keywords=how+to+grow+tomatoes&ie=UTF8&qid=1327692925&rnid=1000">
<span class="refinementLink">Health, Fitness & Dieting</span><span class="narrowValue"> (3)</span>
</a>
</li>
<li style="margin-left: 6px;">
<a href="/s/ref=sr_nr_n_2?rh=k%3Ahow+to+grow+tomatoes%2Cn%3A283155%2Cp_n_feature_browse-bin%3A618073011%2Cn%3A%211000%2Cn%3A6&bbn=1000&sort=salesrank&keywords=how+to+grow+tomatoes&ie=UTF8&qid=1327692925&rnid=1000">
<span class="refinementLink">Cookbooks, Food & Wine</span><span class="narrowValue"> (2)</span>
</a>
</li>
</ul>
我要提取
工艺品,爱好&amp;家庭等在span标签中关闭
答案 0 :(得分:4)
将提供的表达式置于面值 - 即忽略表达式与其描述之间的任何矛盾 - 您可以使用以下表达式排除包含a的li
元素strong
孩子:
//div[@id="divid"]/ul[@id="ulid"]/li[not(strong)]/a