python爬虫英文怎么说_python爬虫腾讯翻译实现中英翻译
[Python] 純文本查看 復制代碼import requests
import json
text = input("輸入翻譯內容:")
a = 0 # 中文數
b = 0 # 非中文數
to = "0"
from_ = "1"
for i in text:
if u'\u4e00' <= i <= u'\u9fff':
a += 1
else:
b += 1
if a > b: # 當中文數量大于非中文數量時,就中文轉英文
to = "1"
from_ = "0"
'''
from =1 to = 0 ---》英-中
from =0 to = 1 ---》中-英
'''
data = {"from": from_,
"to": to,
"sourceText": text,
"type": "1",
"latitude": "1",
"longitude": "1",
"platform": "H5"}
url = "https://m.fanyi.qq.com/translate"
headers = {
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"}
response = requests.post(url, headers=headers, data=data)
html = response.content.decode()
html_dict = json.loads(html)
print("翻譯結果:", html_dict["targetText"])
總結
以上是生活随笔為你收集整理的python爬虫英文怎么说_python爬虫腾讯翻译实现中英翻译的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 这份代码是不是应该有BUG!!
- 下一篇: PB datawindow中的文本调整打