今天看了一下买来的C#项目书,感觉有点不可理喻,简直就是作者用来圈钱的,视频敷衍了事,源代码莫名其妙。。。唉。。。不过今天还是学了新东西,是一个Python爬虫脚本,虽说也是云里雾里,但是也算一个小进步,千里之行始于足下么,下面就把代码给贴出来。
import urllib.request
import urllib.parse
import json
content = input(‘please input what you want to translate : ‘)
url = ‘http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=null‘
data = {}
data[‘type‘] = ‘AUTO‘
data[‘i‘] = content
data[‘doctype‘] = ‘json‘
data[‘xmlVersion‘] = ‘1.8‘
data[‘keyfrom‘] = ‘fanyi.web‘
data[‘ue‘] = ‘UTF-8‘
data[‘action‘] = ‘FY_BY_ENTER‘
data[‘typoResult‘] = ‘true‘
data = urllib.parse.urlencode(data).encode(‘utf-8‘)
response = urllib.request.urlopen(url,data)
html = response.read().decode(‘utf-8‘)
target = json.loads(html)
print(‘The result is %s‘ % (target[‘translateResult‘][0][0][‘tgt‘]))
还剩45天,到底能学成什么样我也不知道,但是未来不迎,当时不杂,过往不恋。万事只需冷静应对,笑看人生~~~