我尝试抓取使用Scrapy以下网址: http://www.walgreens.com/search/results.jsp?Ntt=bounty+paper+towelScrapy反应不完全
,但返回的URL是不完整的。因为当我做
scrapy shell the_url_above
然后
view(response)
的网页只是不完全加载。所以我的问题是:
- 这个问题的原因是什么? (为什么我没有得到一个404,但一个不完整的答复)
- 什么是一些潜在的方式来处理它?
我尝试抓取使用Scrapy以下网址: http://www.walgreens.com/search/results.jsp?Ntt=bounty+paper+towelScrapy反应不完全
,但返回的URL是不完整的。因为当我做
scrapy shell the_url_above
然后
view(response)
的网页只是不完全加载。所以我的问题是:
该页面的数据似乎已经用JavaScript加载。如果您检查页面(如萤火网络选项卡上),你会看到,一旦基地页面加载的产品正在由JavaScript,它发送POST请求http://www.walgreens.com/svc/products/search
与内容加载:
{"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发送此请求为:
yield Request('http://www.walgreens.com/svc/products/search',
method='POST',
body=<the json from above>)
而且您应该收到一个完整的产品数据的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