Introduction
Learning English is difficult, but it's fun———— Learning English
Do you need to read the original English web pages, news and documents? Do you always need to stop to look up the dictionary, stumble, or even find it difficult to continue?
Xiaobian often encounters this problem. Although learning Python and English is enough, it seems that children at home need to be more refined. Children at home often ask me to help complete her homework. To tell the truth, I'm very angry? A single translation is OK. It can't be translated even if it's connected
In this issue, I would like to recommend a black technology auxiliary tool for translation, which can help you learn English slowly~
It can not only help you translate Chinese with one click, but also translate English, hey hey! Then follow Xiaobian to have a try!
text
This article is an interface applet based on Tkinter! Follow Me with Xiaobian~
The interface selected here is Youdao translation drop link:
fanyi.youdao.com/
(1) send a request to the web page.
class YouDao(object): def __init__(self): pass def crawl(self, content): # Enter the web page source code search.js Click to enter the search to see if there are three 'salt' '' 'sign' 'lts', which proves that the found files are correct. Copy the web page search JS format conversion to create JS files lts = int(time.time() * 1000) # Time stamp to millisecond time stamp to time stationmaster tool timestamp = lts + random.randint(0, 10) # sign: n.md5("fanyideskweb" + e + i + "Tbh5E8=q6U3EXe+&L[4c@") a = "fanyideskweb" e = content i = str(timestamp) d = "Tbh5E8=q6U3EXe+&L[4c@" sign = hashlib.md5((a+e+i+d).encode('utf-8')).hexdigest() data = { 'i': content, 'from': 'AUTO', 'to': 'AUTO', 'smartresult': 'dict', 'client': 'fanyideskweb', 'salt': timestamp, 'sign': sign, 'lts': lts, 'bv': 'dd67d51c2bbb03cccdbcfa48735ba27f', 'doctype': 'json', 'version': '2.1', 'keyfrom': 'fanyi.web', 'action': 'FY_BY_CLICKBUTTION' } data = urllib.parse.urlencode(data).encode('utf-8') headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36', 'Cookie': 'OUTFOX_SEARCH_USER_ID=406040753@221.204.120.171; DICT_UGC=be3af0da19b5c5e6aa4e17bd8d90b28a|; JSESSIONID=abcJcdIfpYuE3eNgyi3Dx; OUTFOX_SEARCH_USER_ID_NCOO=902501357.1460881; user-from=http://www.youdao.com/; from-page=http://www.youdao.com/; _ntes_nnid=250706e8175b6796101a34821527eb62,1612611490655; DICT_SESS=v2|qKlfGGGmbVOAOfp40fQy0UWhfPuOMzWRlfk4Qz0LYERTu0flfn4Ul0l50He40fOW0TK6LlWRf6B0w46LYmh46F0JShMTLOfOm0; DICT_LOGIN=1||1612612510172; STUDY_SESS=EtwvT8KhyXqnLv8r0zdde8FcMOICmtZSIsltEiKZiAQq44wPVNN6PupszWYKIkBKfygQdvKlXU7p3aF+p0H6VcZLod3s2Bld6H/EWIphmRS92qG/3vVhSxHFAXq2yJp8QyH/R6RElNstKdVewVkZp+NyGWhzlamzU5dl6aBiyQ2Ybdo8MpdaPQB26wR6JPAU+P6MxCmnJEvne6pPMc9TTJJnThNrM7aj0X5LVpSBvjZ0h3M1drl4ZsmtkumIhrpyk1pBNevj8UEmS52Cj8DFo+yez89Xrbg4rxsvfSmuH21KlOh/Gwx6G1S/X4FQ7qd/Z2lDsk6Qgl21Md/1bCxa/orloi9qObM4N2yVCVhvkDdg5ILQezB8iskCpUa+ESZk; STUDY_INFO=UID_10AE81F6EF9DD9807BAC3FF3FD6407BA|4|1456638755|1612612364854; ___rl__test__cookies=1612663596564', 'Referer': 'http://fanyi.youdao.com/', } request = urllib.request.Request('http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule', method='POST', data=data, headers=headers) response = urllib.request.urlopen(request) result_str = response.read().decode('utf-8') result_dict = json.loads(result_str) result = result_dict["translateResult"][0][0]["tgt"] return result Copy code
(2) Set the interface window data.
class Application(object): def __init__(self): # Create a window self.window = Tk() # Window title self.window.title(u'Chinese English translation applet') # Set window size and position self.window.geometry("280x350+400+150") # Input box self.entry = Entry(self.window) self.entry.place(x=10, y=10, width=200, height=25) # Width = width, height = height # Query button self.button = Button(self.window, text=u'query', command=self.function) # command executes this function self.button.place(x=220, y=10, width=50, height=25) # Translation result title self.label = Label(self.window, text=u'Translation results:') self.label.place(x=10, y=45) # Translation box self.text = Text(self.window, background='#ccc') # Set background color self.text.place(x=10, y=75, width=260, height=265) Copy code
(3) Storage of translation results.
def function(self): # Get the user's value from the input box content = self.entry.get() # Send the value to Youdao server for translation youdao = YouDao() result = youdao.crawl(content) # Put the results in the translation box self.text.delete(1.0, END) # Delete each query first self.text.insert(END, result) # The last position of the inserted text is imported into the END library def run(self): self.window.mainloop() Copy code
(4) Screenshot of interface translation program.
I am too easy to be satisfied. For example, when the sky is blue and the clouds are white, I am very happy and feel that everything has become particularly beautiful. “
1.1 the translated sentence in English: "It was sunny and very hot today,I got up early."
summary
Hahaha! This article is written here. This translation software can be used by children with poor English at home, making learning easier~
Free source code collection office:
For the complete project source code + material source code base, see: like, pay attention to the collection, click my avatar private letter 666, click the link to get it from me!
Your support is my biggest motivation!! remember the third consecutive oh ~mua, welcome to read the previous articles~