Easy to use Request:
#_ *_ coding:utf-8 _*_ "Created on July 14, 2018 @author:sss" "Import requestsimport json# Select a different proxy according to the protocol type proxies = {" H TTP ":" 118.190.95.43:9001 "," https ":" 49.79.156.109:8000 ",}headers = {" Connection ":" Keep-alive ", "Accept": "Application/json, Text/javascript, */*; q=0.01 "," X-requested-with ":" XMLHttpRequest "," user-agent ":" mozilla/5.0 (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/67.0.3396.99 safari/537.36 "," Content-type ":" Application/x-w ww-form-urlencoded; Charset=utf-8 "," Referer ":" http://fanyi.youdao.com/"}formdata = {" I ": ' Hello '," from ":" AUTO " , "to": "AUTO", "Smartresult": "Dict", "Client": "Fanyideskweb", "salt": "1531403738742", #这个 Should be a time stamp "sign": "Ffa2b29fe52953208226d97a174bcea7", #应该是根据时间戳 + you want to translate the content encrypted after the generated validation field "DOCTYPE": "JSON", "V Ersion ":" 2.1 "," Keyfrom ":" Fanyi.web "," Action ":" Fy_by_realtime ", "Typoresult": "false"}# url = "Http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartr Esult=ugc&sessionfrom=null "url =" Http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule "# Http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule to remove _o response = requests.post (URL, data = Formdata, headers = headers, proxies = proxies) print (Response.text.encode (encoding= ' utf_8 ')) #如果是json文件可以直接显示print ( Response.json ()) html = Response.texttarget = json.loads (HTML) print ("Translation result:%s"% (target[' translateresult '][0][0][' TGT '])) #读出结果 # returns Cookiejar object: Cookiejar = response.cookies# converts cookiejar to dictionary: cookiedict = requests.utils.dict_from_ Cookiejar (Cookiejar) print (Cookiejar) print (cookiedict)
Application of requests in 10-python