def _search(self, limit, format):
'''
Returns a list of result objects, with the url for the next page bing search url.
Image filters:
Array of strings that filter the response the API sends based on size, aspect, color, style, face or
any combination thereof. Valid values are: Size:Small, Size:Medium, Size:Large, Size:Width:[Width],
Size:Height:[Height], Aspect:Square, Aspect:Wide, Aspect:Tall, Color:Color, Color:Monochrome, Style:Photo,
Style:Graphics, Face:Face, Face:Portrait, Face:Other.
'''
url = self.QUERY_URL.format(requests.utils.quote("'{}'".format(self.query)), min(50, limit),
self.current_offset, format,
requests.utils.quote("'{}'".format(self.image_filters)))
r = requests.get(url, auth=("", self.api_key))
try:
json_results = r.json()
except ValueError as vE:
if not self.safe:
raise PyBingImageException("Request returned with code %s, error msg: %s" % (r.status_code, r.text))
else:
print ("[ERROR] Request returned with code %s, error msg: %s. \nContinuing in 5 seconds." % (
r.status_code, r.text))
time.sleep(5)
packaged_results = [ImageResult(single_result_json) for single_result_json in json_results['d']['results']]
self.current_offset += min(50, limit, len(packaged_results))
return packaged_results
评论列表
文章目录