py_bing_search.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:Genum 作者: la0rg 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号