(self, query_text:str, from_language:str='auto', to_language:str='en', **kwargs)
return data if is_detail_result else data[0]['translations'][0]['text']
https://bing.com/Translator, https://cn.bing.com/Translator.
        :param query_text: str, must.
        :param from_language: str, default 'auto'.
        :param to_language: str, default 'en'.
        :param **kwargs:
                :param if_use_cn_host: boolean, default None.
                :param if_ignore_limit_of_length: boolean, default False.
                :param is_detail_result: boolean, default False.
                :param timeout: float, default None.
                :param proxies: dict, default None.
                :param sleep_seconds: float, default `random.random()`.
        :return: str or list
https://bing.com/Translator, https://cn.bing.com/Translator.
        :param query_text: str, must.
        :param from_language: str, default 'auto'.
        :param to_language: str, default 'en'.
        :param **kwargs:
                :param if_use_cn_host: boolean, default None.
                :param if_ignore_limit_of_length: boolean, default False.
                :param is_detail_result: boolean, default False.
                :param timeout: float, default None.
                :param proxies: dict, default None.
                :param sleep_seconds: float, default `random.random()`.
        :return: str or list
https : // bing . com / Translator https : // cn . bing . com / Translator . : param query_text : str must . : param from_language : str default auto . : param to_language : str default en . : param ** kwargs : : param if_use_cn_host : boolean default None . : param if_ignore_limit_of_length : boolean default False . : param is_detail_result : boolean default False . : param timeout : float default None . : param proxies : dict default None . : param sleep_seconds : float default random . random () . : return : str or list
def bing_api(self, query_text:str, from_language:str='auto', to_language:str='en', **kwargs) -> Union[str,list]:
        """
        https://bing.com/Translator, https://cn.bing.com/Translator.
        :param query_text: str, must.
        :param from_language: str, default 'auto'.
        :param to_language: str, default 'en'.
        :param **kwargs:
                :param if_use_cn_host: boolean, default None.
                :param if_ignore_limit_of_length: boolean, default False.
                :param is_detail_result: boolean, default False.
                :param timeout: float, default None.
                :param proxies: dict, default None.
                :param sleep_seconds: float, default `random.random()`.
        :return: str or list
        """
        use_cn_condition = kwargs.get('if_use_cn_host', None) or self.request_server_region_info.get('countryCode')=='CN'
        self.host_url = self.cn_host_url if use_cn_condition else self.en_host_url
        self.api_url = self.host_url.replace('Translator', 'ttranslatev3')
        self.host_headers = self.get_headers(self.host_url, if_api=False)
        self.api_headers = self.get_headers(self.host_url, if_api=True)
        is_detail_result = kwargs.get('is_detail_result', False)
        timeout = kwargs.get('timeout', None)
        proxies = kwargs.get('proxies', None)
        sleep_seconds = kwargs.get('sleep_seconds', random.random())
        if_ignore_limit_of_length = kwargs.get('if_ignore_limit_of_length', False)
        query_text = self.check_query_text(query_text, if_ignore_limit_of_length)
    
        with requests.Session() as ss:
            host_html = ss.get(self.host_url, headers=self.host_headers, timeout=timeout, proxies=proxies).text
            self.host_info = self.get_host_info(host_html)

            if not self.language_map:
                self.language_map = self.host_info.get('language_map')
            from_language, to_language = self.check_language(from_language, to_language, self.language_map,
                                                             output_zh=self.output_zh,output_auto=self.output_auto)
            # params = {'isVertical': '1', '': '', 'IG': self.host_info['ig'], 'IID': self.host_info['iid']}
            self.api_url = self.api_url + '?isVertical=1&&IG={}&IID={}'.format(self.host_info['ig'],self.host_info['iid'])

            if not self.tk or time.time() - self.first_time > 3500: #3600
                self.tk = self.get_tk(host_html)
            form_data = {
                'text': query_text,
                'fromLang': from_language,
                'to': to_language,
            }
            form_data.update(self.tk)
            r = ss.post(self.api_url, headers=self.host_headers, data=form_data, timeout=timeout, proxies=proxies)
            r.raise_for_status()
            data = r.json()
        time.sleep(sleep_seconds)
        self.query_count += 1
        return data if is_detail_result else data[0]['translations'][0]['text']
def bing_api ( self , query_text : str , from_language : str = 'auto' , to_language : str = 'en' , * * kwargs ) -> Union [ str , list ] : use_cn_condition = kwargs . get ( 'if_use_cn_host' , None ) or self . request_server_region_info . get ( 'countryCode' ) == 'CN' self . host_url = self . cn_host_url if use_cn_condition else self . en_host_url self . api_url = self . host_url . replace ( 'Translator' , 'ttranslatev3' ) self . host_headers = self . get_headers ( self . host_url , if_api = False ) self . api_headers = self . get_headers ( self . host_url , if_api = True ) is_detail_result = kwargs . get ( 'is_detail_result' , False ) timeout = kwargs . get ( 'timeout' , None ) proxies = kwargs . get ( 'proxies' , None ) sleep_seconds = kwargs . get ( 'sleep_seconds' , random . random ( ) ) if_ignore_limit_of_length = kwargs . get ( 'if_ignore_limit_of_length' , False ) query_text = self . check_query_text ( query_text , if_ignore_limit_of_length ) with requests . Session ( ) as ss : host_html = ss . get ( self . host_url , headers = self . host_headers , timeout = timeout , proxies = proxies ) . text self . host_info = self . get_host_info ( host_html ) if not self . language_map : self . language_map = self . host_info . get ( 'language_map' ) from_language , to_language = self . check_language ( from_language , to_language , self . language_map , output_zh = self . output_zh , output_auto = self . output_auto ) # params = {'isVertical': '1', '': '', 'IG': self.host_info['ig'], 'IID': self.host_info['iid']} self . api_url = self . api_url + '?isVertical=1&&IG={}&IID={}' . format ( self . host_info [ 'ig' ] , self . host_info [ 'iid' ] ) if not self . tk or time . time ( ) - self . first_time > 3500 : #3600 self . tk = self . get_tk ( host_html ) form_data = { 'text' : query_text , 'fromLang' : from_language , 'to' : to_language , } form_data . update ( self . tk ) r = ss . post ( self . api_url , headers = self . host_headers , data = form_data , timeout = timeout , proxies = proxies ) r . raise_for_status ( ) data = r . json ( ) time . sleep ( sleep_seconds ) self . query_count += 1 return data if is_detail_result else data [ 0 ] [ 'translations' ] [ 0 ] [ 'text' ]