Scrapy:如何获取分页链接?

问题描述 投票:0回答:1

我尝试在此site上获得分页链接,但无济于事。

蜘蛛:

for next_page in response.css('._3ZWfj::attr(href)').getall():
        if next_page is not None:
            next_page = response.urljoin(next_page)
            yield scrapy.Request(next_page, callback=self.profile_link)

html:

<nav class="_2uKgC" aria-label="Page navigation" data-qa-target="pagination">
  <p>Page 1 of 660</p>
  <ul>
    <li class="ktQcN"><span class="CxgVm _3ZWfj"><svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" class="USD7b MBqXj _3NE5i _2bkBT" role="img" aria-label="Previous page" focusable="false"><polyline fill="none" stroke-linecap="round" points="16 20 8 12 16 4"></polyline></svg></span></li>
    <li><span class="HWGOs _3ZWfj">1</span></li>
    <li class="_35eJJ _2Sm6k"><span class="CxgVm _3ZWfj">...</span></li>
    <li class=""><a href="/usearch?what=Acupuncture&amp;entityCode=PS158&amp;distances=National&amp;pageNum=2&amp;sort.provider=bestmatch" class="_3ZWfj" aria-label="Page 2">2</a></li>
    <li class=""><a href="/usearch?what=Acupuncture&amp;entityCode=PS158&amp;distances=National&amp;pageNum=3&amp;sort.provider=bestmatch" class="_3ZWfj" aria-label="Page 3">3</a></li>
  </ul>
</nav>
scrapy css-selectors
1个回答
0
投票
应该是{'response.css('._ 3ZWfj a :: attr(href)')。getall()']
© www.soinside.com 2019 - 2024. All rights reserved.