【问题标题】:Scray shell URL returns 404 for endless scrollScray shell URL 返回 404 进行无限滚动
【发布时间】:2021-04-21 04:47:53
【问题描述】:

我正在培训如何在命令提示符下使用 scrapy shell,这是 URL https://shopee.com.my/shop/145423/followers/?__classic__=1

对于 google chrome 开发人员(按 F12)和 Network 部分,我已清除所有内容并浏览网站并获得此链接 https://shopee.com.my/shop/145423/followers/?offset=60&limit=20&offset_of_offset=0&_=1610787400133 该链接应该返回一些数据,但在尝试时

scrapy shell https://shopee.com.my/shop/145423/followers/?offset=60&limit=20&offset_of_offset=0&_=1610787400133

我收到 404 作为响应。 我认为有一个弹出窗口需要用户单击语言,这就是问题所在 如何处理或跳过这样的弹出窗口?

【问题讨论】:

  • 您是否尝试将 URL 用引号括起来,例如 scrapy shell "the_url"?也许shell将&limit=20等解释为设置环境变量?
  • 我已经尝试过你的建议,但同样的问题。我已经导出了response.text 并注意到那部分<div class="label-select-language L24">Select Your Language</div> 所以我认为这与弹出窗口有关
  • 应该与弹窗无关。 404 的意思是“没有这样的页面”,而弹出窗口来自您成功加载的页面,所以现在这是一个完全不同的问题。

标签: python scrapy


【解决方案1】:

使用用户代理。你也可以在command line中使用User Agent

 headers={'User-Agent': 'Mybot'}
>>> r = scrapy.Request(url, headers=headers)
>>> fetch(r)
2021-01-16 16:53:11 [scrapy.downloadermiddlewares.redirect] DEBUG: Redirecting (302) to <GET https://shopee.com.my/shop/145423/followers/?offset=60&limit=20&offset_of_offset=0&_=1610787400133&__classic__=1> from <GET https://shopee.com.my/shop/145423/followers/?offset=60&limit=20&offset_of_offset=0&_=1610787400133>
2021-01-16 16:53:11 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://shopee.com.my/shop/145423/followers/?offset=60&limit=20&offset_of_offset=0&_=1610787400133&__classic__=1> (referer: None)
>>> response.status
200
>>> 

【讨论】:

  • 太棒了。你能解释一下Mybot 用作标题用户代理吗?
  • 我试过这样的一行response.css('li.clickable_area::text').getall(),但我得到的只是换行符,尽管有response.text,数据就在那里。!!
  • 用户代理可以是 firefox, chrome , details developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent 。 response.css('li.clickable_area a::text').getall() 。希望对您有所帮助。
  • 我认为你需要选择合适的 CSS 选择器或使用过滤器
  • 因为这是 url 的一部分。您可以在 response.css('li.clickable_area'): ... part =i.css('a::attr("href")').get () ... response.urljoin(部分)
猜你喜欢
  • 2023-04-01
  • 1970-01-01
  • 2016-04-02
  • 2018-09-21
  • 2019-07-05
  • 1970-01-01
  • 2012-10-04
  • 1970-01-01
  • 2013-07-02
相关资源
最近更新 更多