我正在將我的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. 在ColdFusion中使用Bing Web Search API
- 4. Bing Web Search API停止工作?
- 5. Bing Web Search API和黑名單(python)
- 6. 能Bing搜索API V5搜索非英文新聞文章
- 7. 使用Bing V5 API時獲得不同結果vs bing.com
- 8. 如何限制Bing搜索API V5搜索網站
- 9. bing search api中的單個空間問題?
- 10. 使用BING SEARCH API時,如何忽略重複結果?
- 11. 從Bing Web Search API中檢索剩餘事務
- 12. 如何在Javascript中爲Bing Azure Search API設置AppId?
- 13. 如何從Bing Web Search API獲取廣告信息?
- 14. 如何檢查Bing Web Search API v5.0的剩餘配額
- 15. Bing搜索API
- 16. bing api搜索
- 17. 爲Bing API
- 18. Microsoft認知服務 - Bing新聞搜索API V5。這麼多的誤解
- 19. 用Bing自定義搜索替換GCSE
- 20. 從bing地圖替換EntityCollection類
- 21. Bing Maps API - setBounds
- 22. Google Search API ruby
- 23. Google API for Search
- 24. GAE Search API number_found_accuracy
- 25. stackoverflow search api
- 26. freebase search api
- 27. itunes-search API Android
- 28. Google Custom Search API
- 29. Bing Azure搜索api
- 30. Bing是如何轉換GeoJSON屬性的Bing Maps API描述?