无法将两个表达式粘合到一个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&geo_location_terms=Los%20Angeles%2C%20CA&page=2" data-page="2" data-analytics="{"click_id":132,"module":1,"listing_page":2}" data-remote="true" data-impressed="1">2</a></li><li><a href="/search?search_terms=pizza&geo_location_terms=Los%20Angeles%2C%20CA&page=3" data-page="3" data-analytics="{"click_id":132,"module":1,"listing_page":3}" data-remote="true" data-impressed="1">3</a></li><li><a href="/search?search_terms=pizza&geo_location_terms=Los%20Angeles%2C%20CA&page=4" data-page="4" data-analytics="{"click_id":132,"module":1,"listing_page":4}" data-remote="true" data-impressed="1">4</a></li><li><a href="/search?search_terms=pizza&geo_location_terms=Los%20Angeles%2C%20CA&page=5" data-page="5" data-analytics="{"click_id":132,"module":1,"listing_page":5}" data-remote="true" data-impressed="1">5</a></li><li><a href="/search?search_terms=pizza&geo_location_terms=Los%20Angeles%2C%20CA&page=2" data-page="2" data-analytics="{"click_id":132}" data-remote="true" class="next ajax-page" data-impressed="1">Next</a></li></ul></div>
答案 0 :(得分:1)
有两种方法可以组合两个XPath表达式。例如,一种方法是使用union运算符&#34; |&#34;。是否合适的操作符取决于您想要实现的目标。遗憾的是,您忘了告诉我们您想要达到的目标,因此可能不适合您的目的。