如何将两个xpath表达式合并为一个?

时间:2017-05-13 21:07:42

标签: xpath

无法将两个表达式粘合到一个xpath中。他们都属于同一个班级"分页"。我需要在循环中使用它。我像这样单独尝试:

//div[@class='pagination']//a/@href
//div[@class='pagination']//a[contains(@class,'next')]/@href

表达式的元素:

<div class="pagination"><p><span>Showing</span>1-30
of 483<span>results</span></p><ul><li><span class="disabled">1</span></li><li><a href="/search?search_terms=pizza&amp;geo_location_terms=Los%20Angeles%2C%20CA&amp;page=2" data-page="2" data-analytics="{&quot;click_id&quot;:132,&quot;module&quot;:1,&quot;listing_page&quot;:2}" data-remote="true" data-impressed="1">2</a></li><li><a href="/search?search_terms=pizza&amp;geo_location_terms=Los%20Angeles%2C%20CA&amp;page=3" data-page="3" data-analytics="{&quot;click_id&quot;:132,&quot;module&quot;:1,&quot;listing_page&quot;:3}" data-remote="true" data-impressed="1">3</a></li><li><a href="/search?search_terms=pizza&amp;geo_location_terms=Los%20Angeles%2C%20CA&amp;page=4" data-page="4" data-analytics="{&quot;click_id&quot;:132,&quot;module&quot;:1,&quot;listing_page&quot;:4}" data-remote="true" data-impressed="1">4</a></li><li><a href="/search?search_terms=pizza&amp;geo_location_terms=Los%20Angeles%2C%20CA&amp;page=5" data-page="5" data-analytics="{&quot;click_id&quot;:132,&quot;module&quot;:1,&quot;listing_page&quot;:5}" data-remote="true" data-impressed="1">5</a></li><li><a href="/search?search_terms=pizza&amp;geo_location_terms=Los%20Angeles%2C%20CA&amp;page=2" data-page="2" data-analytics="{&quot;click_id&quot;:132}" data-remote="true" class="next ajax-page" data-impressed="1">Next</a></li></ul></div>

1 个答案:

答案 0 :(得分:1)

有两种方法可以组合两个XPath表达式。例如,一种方法是使用union运算符&#34; |&#34;。是否合适的操作符取决于您想要实现的目标。遗憾的是,您忘了告诉我们您想要达到的目标,因此可能不适合您的目的。