使用Python通过Azure API搜索Bing
发布时间:2021-01-11 11:37:32 所属栏目:Python 来源:互联网
导读:如何使用关键词搜索Bing的图像? 我可以使用以下方式搜索Google: import urllib2import jsoncredentialGoogle = # Google credentials from: https://console.developers.google.com/searchString = Xbox%20Onetop = 20offset = 0
如何使用关键词搜索Bing的图像? 我可以使用以下方式搜索Google: import urllib2 import json credentialGoogle = '' # Google credentials from: https://console.developers.google.com/ searchString = 'Xbox%20One' top = 20 offset = 0 while offset < top: url = 'https://ajax.googleapis.com/ajax/services/search/images?' + 'v=1.0&q=%s&start=%d&userip=%s' % (searchString,offset,credentialGoogle) request = urllib2.Request(url) response = urllib2.urlopen(request) results = json.load(response) # process results offset += 4 # since Google API only returns 4 search results at a time Bing的等价物是什么?据推测它开始于: keyBing = '' # Bing key from: https://datamarket.azure.com/account/keys credentialBing = '' # same as key? searchString = '%27Xbox+One%27' top = 20 offset = 0 url = 'https://api.datamarket.azure.com/Bing/Search/Image?' + 'Query=%s&$top=%d&$skip=%d&$format=json' % (searchString,top,offset) 但凭证是如何设置的? 解决方法Bing等价物将是:keyBing = '' # get Bing key from: https://datamarket.azure.com/account/keys credentialBing = 'Basic ' + (':%s' % keyBing).encode('base64')[:-1] # the "-1" is to remove the trailing "n" which encode adds searchString = '%27Xbox+One%27' top = 20 offset = 0 url = 'https://api.datamarket.azure.com/Bing/Search/Image?' + 'Query=%s&$top=%d&$skip=%d&$format=json' % (searchString,offset) request = urllib2.Request(url) request.add_header('Authorization',credentialBing) requestOpener = urllib2.build_opener() response = requestOpener.open(request) results = json.load(response) # process results 解决方案归功于:http://www.guguncube.com/2771/python-using-the-bing-search-api (编辑:哈尔滨站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- python optparse,可选选项的默认值
- Python:ndarray.flatten(‘F’)有否相反?
- python – 从scipy.stats … rvs和numpy.random的随机抽取之
- 在Python中处理不同类型的规范方法是什么?
- 什么是Perlbrew的Python等价物?
- python – 如何在TensorFlow中实现递归神经网络?
- Python:如何找到使用matplotlib绘制的图形的斜率?
- 使用Django Crispy Forms渲染单独的MultiWidget字段
- python – 浏览器和wget加载JPEG不同?
- Python:“subprocess.Popen”检查成功和错误