Guest User

Untitled

a guest
Jun 6th, 2016
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*- ?
  2. import requests
  3. import json
  4. import sys
  5. import codecs
  6.  
  7. def GetJSON(word):
  8.   url = "https://ru.wiktionary.org//w/api.php?action=query&titles=%s&prop=revisions&rvprop=content&format=json"
  9.   url = url%word
  10.   answ = requests.get(url).content
  11.   data = json.loads(answ)
  12.   str = json.dumps(data, ensure_ascii=False, indent=4)
  13.   return json.loads(str)
  14.  
  15. outfile = codecs.open("filename", 'w', "utf-8")
  16. str = json.dumps(GetJSON("кот"), ensure_ascii=False, indent=4)
  17. outfile.write(str)
  18. outfile.close()
  19.  
  20. print GetJSON("кот")["query"]["pages"]["12766"]["title"]
RAW Paste Data