恶心的反应

2024-04-29 14:25:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用Scrapy抓取以下网址: http://www.walgreens.com/search/results.jsp?Ntt=bounty+paper+towel

但是返回的URL不完整。因为当我这么做的时候

scrapy shell the_url_above

那么

^{pr2}$

这个网页没有完全加载。所以我的问题是:

  1. 这个问题的原因是什么?(为什么我没有收到404,但回复不完整)
  2. 有什么可能的方法来处理它?在

Tags: comhttpurlsearchwwwtowelresultspaper
1条回答
网友
1楼 · 发布于 2024-04-29 14:25:51

该页面的数据似乎是用javascript加载的。如果您检查页面(例如firebug network选项卡),您会看到一旦加载了基本页面,javascript就会加载产品,javascript会向http://www.walgreens.com/svc/products/search发送一个POST请求,其中包含以下内容:

{"p":"1",  # seems to be page number
"s":"15",  # page size
"sort":"relevance",
"view":"allView",
"geoTargetEnabled":false,
"q":"bounty paper towel",  # search query
"requestType":"search",
"deviceType":"desktop"}

您可以使用scrapy发送此请求:

^{pr2}$

您应该会收到一个json对象,其中充满了产品数据。在

您甚至可以通过以下链接在浏览器中查看响应: http://www.walgreens.com/svc/products/search?p=1&s=15&sort=relevance&view=allView&geoTargetEnabled=false&q=bounty%20paper%20towel&requestType=search&deviceType=desktop

相关问题 更多 >