Skip to main content

microsoft cn.bing translator

Project description

微软bing翻译器python sdk

PyPI version Download count

介绍

微软bing翻译器,支持cn.bing.com和www.bing.com,建议轻量使用,欢迎star、follow、fork。

适用对象

无法或者不便使用微软Azaue Text Translation服务的用户轻量级用户可以使用bing提供的翻译能力。

源码

github

gitee

安装

pip install cn_bing_translator

使用方法

from cn_bing_translator import Translator

if __name__ == "__main__":
    translator = Translator()
    source = "翻译器"
    result = translator.process(source)
    print(result)

默认情况下将自动检测源语言语种,并翻译为英语,如果需要指定其他语种,可以在初始化的时候传入对应的语言代码:

# 传入以下参数初始化一个从英语到日语的翻译器
translator = Translator(fromLang='en', toLang='ja')

具体支持的语言类型和代码请参考微软网站

翻译器初始化的时候,也可以定制user agent:

agent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 Edg/99.0.4844.51'
translator = Translator(agent=agent)

如果有使用代理的需求,可以指定proxy:

proxy = {'https':'http://localhost:8080'}
translator = Translator(proxy=proxy)

默认调用cn.bing.com,如需使用www.bing.com,可以在初始化的时候指定:

translator = Translator(cnBing=False)

需要注意的是,根据bing.com的跳转规则,如果服务器判断是中国区用户访问,即使指定cnBing为False,仍然会自动跳转到cn.bing.com。

注意事项

建议轻量级使用,控制调用量和频率,微软bing翻译器默认带有防滥用措施,频繁发起大量请求可能会触发拦截。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cn_bing_translator-0.0.3.tar.gz (5.1 kB view hashes)

Uploaded Source

Built Distribution

cn_bing_translator-0.0.3-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page