我正在将我的webstite表单Bing Azure API(v2)迁移到新的Bing V5搜索API。
在旧的API上,一个对象使用这个“__next”来告诉他是否有其他东西。
但是在新的API上,json不再返回这个。
我正在升级我的分页,我不知道如何做到这一点没有这个元素。
任何人都知道什么在新的API中取代它?
我无法在其迁移指南或新的V5 API指南中找到任何信息。
谢谢。bing search api v5“__next”替换?
2
A
回答
0
约翰是对的。您可以使用count
和offset
params结合totalEstimatedMatches
从返回的第一个对象的json中的值。
例子:想象一下,你爱橡胶duckies这么多,你要在包含术语所有脑干的每一个网页的“橡胶鸭子”。这是不是互联网如何运作。但是,不要自杀,但Bing知道很多关于含有“橡皮鸭”的网页,你需要做的只是通过Bing知道并欢喜的'橡皮鸭'相关网站分页。
首先,我们需要通过传递“橡胶鸭子”,以它来告诉API,我们希望“一些”的结果(的“一些”是由
count
PARAM定义的值,50为最大值) 。接下来,我们需要查看返回的第一个JSON对象;这将告诉我们在一个名为
totalEstimatedMatches
的字段中Bing知道了多少个“橡皮鸭”的网站。由于我们对橡胶鸭子相关网站的渴求永无止境,我们要建立一个while循环是交替的B/W查询和递增
offset
并不会停止,直到totalEstimatedMatches
和偏移量是count
距离相隔。
下面是一些Python代码澄清:
>>> import SomeMagicalSearcheInterfaceThatOnlyNeeds3Params as Searcher
>>>
>>> SearcherInstance = Searcher()
>>> SearcherInstance.q = 'rubber-ducky'
>>> SearcherInstance.count = 50
>>> SearcherInstance.offset = 0
>>> SearcherInstance.totalEstimatedMatches = 0
>>>
>>> print SearcherInstance.preview_URL
'https://api.cognitive.microsoft.com/bing/v5.0/images/search?q=rubber%2Dducky&count=50&offset=0'
>>>
>>> json_return_object = SearcherInstance.search_2_json()
>>>
>>> ## Python just treats JSON as nested dictionaries.
>>> tem = json_return_object['webPages']['totalEstimatedMatches']
>>> print tem
9500000
>>> num_links_returned = len(json_return_object['webPages']['value'])
>>> print num_links_returned
50
>>>
>>> ## We'll set some vals manually then make our while loop.
>>> SearcherInstance.offset += num_links_returned
>>> SearcherInstance.totalEstimatedMatches = tem
>>>
>>> a_dumb_way_to_store_this_much_data = []
>>>
>>> while SearcherInstance.offset < SearcherInstance.totalEstimatedMatches:
>>> json_response = SearcherInstance.search_2_json()
>>> a_dumb_way_to_store_this_much_data.append(json_response)
>>>
>>> actual_count = len(json_return_object['webPages']['value'])
>>> SearcherInstance.offset += min(SearcherInstance.count, actual_count)
希望这有助于一点。
0
你应该阅读totalEstimatedMatches值第一次调用API,然后使用&计数和&通过结果偏移参数页面如下描述:https://msdn.microsoft.com/en-us/library/dn760787.aspx。
相关问题
- 1. bing search api ajax不工作
- 2. 使用PHP/cURL查询Azure认知服务 - Web Search API v5
- 3. Bing Web Search API和黑名单(python)
- 4. 使用Bing V5 API时获得不同结果vs bing.com
- 5. 如何限制Bing搜索API V5搜索网站
- 6. bing search api中的单个空间问题?
- 7. Bing搜索API
- 8. Microsoft认知服务 - Bing新闻搜索API V5。这么多的误解
- 9. 用Bing自定义搜索替换GCSE
- 10. stackoverflow search api
- 11. Google API for Search
- 12. freebase search api
- 13. Bing是如何转换GeoJSON属性的Bing Maps API描述?
- 14. 使用bing api xslt
- 15. bing web查询Api phonegap android
- 16. Google Search API for C#
- 17. iTunes Search API in Rails
- 18. 使用bing搜索API
- 19. Google Goggles或Visual Search的API?
- 20. Bing Maps v8 JS API
- 21. Bing地图API - 删除PIN
- 22. 如何用python bing替换单词拼写更正建议
- 23. Bing Api如何制作过滤器
- 24. Strange Youtube Search API行为
- 25. Swift 2 - sharedApplication() - Apple Music Search Api
- 26. 查询Google Search Console API PHP
- 27. Jsoup 404工作网站应(Bing API)
- 28. Bing新闻搜索API与Java
- 29. 有没有办法从Bing SOAP Search Service获取地址?
- 30. 新Bing API PHP示例不起作用