一个翻译的程序,只支持中译英,抓的360的接口
一个使用input控制台输入开始翻译,一个使用控制台带参数翻译。
一个使用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)
1 条评论
陈吒诹:文章真不错https://www.hzdimai.com/cctv/92707814280.html