【问题标题】:Scrapy: How to get the number of pages?Scrapy:如何获取页数?
【发布时间】:2020-06-17 00:02:20
【问题描述】:

我正在尝试获取此 site 的页数,但没有任何效果。

response.css('._2uKgC p::text').getall()

html:

<nav class="_2uKgC" aria-label="Page navigation" data-qa-target="pagination">
<p class="">Page 2 of 209</p>
<ul>...</ul></nav>

我做错了什么?

【问题讨论】:

  • 该元素在 html 中不存在,您可以检查“查看页面源代码”来检查您获得的 HTML,而不是检查元素。
  • 我看了,但不明白它是如何工作的。你能帮帮我吗?

标签: python html scrapy css-selectors


【解决方案1】:

您需要从 HTML 代码中获取 sessionIdrequestId,然后请求此 URL:

f"https://www.healthgrades.com/api3/usearch?where=CA&sessionId={sessionId}&requestId={requestId}&sort.provider=bestmatch&source=init&what=Acupuncture&category=provider&cid&debug=false&debugParams=false&isPsr=false&isFsr=false&isFirstRequest=true&pageNum=1&userLocalTime=23%3A55"

解析 JSON 响应后,您会发现 ["search"]["totalPages"](和 ["search"]["totalCount"])值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 2017-08-22
    相关资源
    最近更新 更多