我正在努力将我的webstite从Bing Azure API (v2)迁移到新的Bing V5搜索API。
在旧的API中,一个对象使用这个"__next“来判断他之后是否还有其他的东西。
但是在新的API上,json不再返回它了。
我正在升级我的分页,我不知道如何没有这个元素。
有人知道在新的API中是什么取代了这个吗?
我找不到关于它们的迁移指南或新的V5 API指南的任何信息。
谢谢。
发布于 2016-11-30 18:33:15
约翰是对的。您可以从返回的第一个对象的json中的值与count和offset参数一起使用totalEstimatedMatches。
示例::想象你如此热爱橡胶鸭子,以至于你想要存在的每一个包含“橡胶鸭”这个词的网页。好吧,不幸的是,公元前不是互联网的运作方式。不过,不要自取灭亡,Bing对包含“橡皮鸭”的网页有很多了解,而你所需要做的就是通过Bing所知道的与“橡胶鸭”相关的网站进行分页,并为此感到高兴。
count参数定义的,50是最大值)。totalEstimatedMatches的字段中了解多少个‘橡胶-鸭子’站点。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)希望这能帮点忙。
发布于 2016-11-20 18:40:40
您应该在第一次调用API时读取totalEstimatedMatches值,然后使用&count和&偏移参数页面浏览结果,如下所示:https://msdn.microsoft.com/en-us/library/dn760787.aspx。
https://stackoverflow.com/questions/40628260
复制相似问题