Advertisement
Guest User

vk_docs.py

a guest
Nov 12th, 2016
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. import requests
  2. import json
  3. import sys
  4.  
  5. zapros = 'DSC'
  6. auth = '+++++++' #access_token
  7.  
  8. off = 0
  9.  
  10. requests.packages.urllib3.disable_warnings()
  11.  
  12. r = requests.get('https://api.vk.com/method/docs.search?q=%s&count=1&access_token=%s&v=5.60' % (zapros, auth))
  13. json123 = json.loads(r.text)
  14. if 'error' in json123:
  15.     print json123['error']['error_msg']
  16. else:
  17.     if json123['response']['count'] > 0:
  18.         print 'Total:', json123['response']['count']
  19.         while len(json123['response']['items']) > 0:
  20.             r = requests.get('https://api.vk.com/method/docs.search?q=%s&count=100&offset=%i&access_token=%s&v=5.60' % (zapros, off, auth))
  21.             json123 = json.loads(r.text)
  22.             for i in json123['response']['items']:
  23.                 print 'Owner:', i['owner_id'], '\r\nTitle:', i['title'], '\r\nDownloading...',
  24.                 sys.stdout.flush()
  25.                 try:
  26.                     doc = requests.get(i['url'])
  27.                     fl = open(i['title'], 'wb')
  28.                     fl.write(doc.content)
  29.                     fl.close()
  30.                     print 'OK\r\n'
  31.                 except KeyboardInterrupt:
  32.                     raise KeyboardInterrupt
  33.                 except:
  34.                     print 'Fail\r\n'
  35.                     continue
  36.             off += 100
  37.     else:
  38.         print 'Not found:', zapros
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement