1. Youdao's translation
Pages: www.youdao.com
Fig1
Fig2
Fig3
Fig4
Click "Automatic Translation", select ' Network ' and select ' first ', as follows:
Fig5
Then the following is shown, and the red-framed part is where the code needs to be written:
Fig6
Fig7
Then look at the results of the translation:
Fig8
2.python realization of English-Chinese translation:
Principle: the need to translate the content into Youdao dictionary, and then through the program to climb down the translation results.
1 #-*-coding:utf-8-*-2 """3 Created on Sun 09:36:124 5 @author: 90Zeng6 """7 8 ImportUrllib9 ImportJSONTen One #Note that this is encoded in Unicode, otherwise it will show garbled AContent = input (u"Please enter the content you want to translate:") - #URL is the Response URL in Fig6 -URL ='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc& sessionfrom=http://www.youdao.com/' the #the data format for crawling down is form data in Fig7 -data = {} -data['type'] ='AUTO' -data['I'] =content +data['DOCTYPE'] ='JSON' -data['xmlversion'] ='1.6' +data['Keyfrom'] ='Fanyi.web' Adata['UE'] ='UTF-8' atdata['Typoresult'] ='true' - - #Data Encoding -data =urllib.urlencode (data) - - #crawling content from URLs in the format of data inResponse =urllib.urlopen (URL, data) - #reads the crawled content into the variable string html, toHTML =Response.read () + #converts a string into a dictionary form as shown in Fig8 -target =json.loads (HTML) the #based on the FIG8 format, the final translation results are taken out *result = target["Translateresult"][0][0]['TGT'] $ Panax Notoginseng #Here Unicode display Chinese, avoid garbled - Print(U"translation Result:%s"% (target["Translateresult"][0][0]['TGT']))
Run:
Learning Source: The Little Turtle's video ' 0 basics of getting Started Python '
Python Learning Note: "Crawler + Youdao Dictionary" to achieve a simple English-Chinese translation Program