fork download
  1. # your code goes here
  2. import urllib
  3. import json
  4.  
  5. url='http://f...content-available-to-author-only...o.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict2.top'
  6. content='love'
  7. head={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36'}
  8. proxy_support=urllib.request.ProxyHandler({'http':'182.132.231.234:8118'})
  9. opener=urllib.request.build_opener(proxy_support)
  10. urllib.request.install_opener(opener)
  11. data={}
  12. data['type']='AUTO'
  13. data['i']=content
  14. data['doctype']='json'
  15. data['xmlVersion']='1.8'
  16. data['keyfrom']='fanyi.web'
  17. data['ue']='UTF-8'
  18. data['action']='FY_BY_CLICKBUTTON'
  19. data['typoResult']='true'
  20. data=urllib.parse.urlencode(data).encode('utf-8')
  21. resq=urllib.request.Request(url,data,head)
  22. response=urllib.request.urlopen(resq).read().decode('utf-8')
  23. response=json.loads(response)['translateResult'][0][0]['tgt']
  24. print(content,':',response)
Runtime error #stdin #stdout #stderr 0.01s 10296KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 8, in <module>
AttributeError: 'module' object has no attribute 'request'