一个翻译的程序,只支持中译英,抓的360的接口
一个使用input控制台输入开始翻译,一个使用控制台带参数翻译。

import requests
import json

xxoo = input("请输入要翻译的字、词:")
headers = {"origin": "https://fanyi.so.com",
           "pro": "fanyi",
           "referer": "https://fanyi.so.com/",
           "sec-ch-ua-mobile": "?0",
           "sec-ch-ua-platform": "Windows",
           "sec-fetch-dest": "empty",
           "sec-fetch-mode": "cors",
           "sec-fetch-site": "same-origin",
           "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}
post_data = {"query": xxoo,
             "eng": "0",
             "validate": "",
             "ignore_trans": "0"}
post_url = "https://fanyi.so.com/index/search?eng=0&validate=&ignore_trans=0&query={}"
post_url.format(xxoo)
fanyi = requests.post(post_url, data=post_data, headers=headers)
fanyi_dict = json.loads(fanyi.content.decode())
c = fanyi_dict["data"]["fanyi"]
print("翻译的结果是:", c)

import requests
import json
import sys

xxoo = sys.argv[1]
headers = {"origin": "https://fanyi.so.com",
           "pro": "fanyi",
           "referer": "https://fanyi.so.com/",
           "sec-ch-ua-mobile": "?0",
           "sec-ch-ua-platform": "Windows",
           "sec-fetch-dest": "empty",
           "sec-fetch-mode": "cors",
           "sec-fetch-site": "same-origin",
           "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}
post_data = {"query": xxoo,
             "eng": "0",
             "validate": "",
             "ignore_trans": "0"}
post_url = "https://fanyi.so.com/index/search?eng=0&validate=&ignore_trans=0&query={}"
post_url.format(xxoo)
fanyi = requests.post(post_url, data=post_data, headers=headers)
fanyi_dict = json.loads(fanyi.content.decode())
c = fanyi_dict["data"]["fanyi"]
print("翻译的结果是:", c)

QQ截图20220909022736.png
QQ截图20220909022915.png

最后修改:2022 年 09 月 09 日
如果觉得我的文章对你有用,请随意赞赏