<div id="js-map-search-result-nav" class="lookup-result-guide" style="width: 630px;">
<ul class="c-pagination lookup-result-pagination">
<li class="c-pagination__list">
<a href="/en/tokyo/rstLst/57/" class="c-pagination__target c-pagination__target--prev js-pjax-anchor" rel="prev">« Prev</a>
</li>
<li class="c-pagination__list"><a class="c-pagination__target c-pagination__target--num js-pjax-anchor" href="/en/tokyo/rstLst/54/">54</a></li> <li class="c-pagination__list"><a class="c-pagination__target c-pagination__target--num js-pjax-anchor" href="/en/tokyo/rstLst/55/">55</a></li> <li class="c-pagination__list"><a class="c-pagination__target c-pagination__target--num js-pjax-anchor" href="/en/tokyo/rstLst/56/">56</a></li> <li class="c-pagination__list"><a class="c-pagination__target c-pagination__target--num js-pjax-anchor" href="/en/tokyo/rstLst/57/">57</a></li> <li class="c-pagination__list"><span class="c-pagination__target c-pagination__target--num is-selected">58</span></li> <li class="c-pagination__list"><a class="c-pagination__target c-pagination__target--num js-pjax-anchor" href="/en/tokyo/rstLst/59/">59</a></li> <li class="c-pagination__list"><a class="c-pagination__target c-pagination__target--num js-pjax-anchor" href="/en/tokyo/rstLst/60/">60</a></li>
<li class="c-pagination__list">
<a href="/en/tokyo/rstLst/59/" class="c-pagination__target c-pagination__target--next js-pjax-anchor" rel="next">Next »</a>
</li>
</ul>
1117 - 1160 of 131715
我想知道如何使用xpath获取最后一个li标记的链接,无论使用response.css还是response.xpath
这是我正在编写的代码
for response.xpath中的href(&#39; // * [@ id =&#34; js-map-search-result-nav&#34;] / ul / li [-1] / a / @ HREF&#39): yield response.follow(href,self.parse)
答案 0 :(得分:0)
(//ul[contains(@class,'lookup-result-pagination')]/li)[last()]
或
(//ul[contains(@class,'c-pagination')]/li)[last()]
获取//ul[contains(@class,'lookup-result-pagination')]
这里是css定位器:
ul.c-分页&GT;李:最后子
但是最后的li - 在你的情况下是“下一步”按钮,你需要它还是最后一页?
在这种情况下,您可以使用Xpath检查最后一个li没有下一个文本
(// UL [含有(@类, 'C-分页')] /锂[不(./一个[含有(文本(), '下一步')])])[最后()]