Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import urllib.request
  2. import urllib.error
  3. import random
  4. import http.client
  5.  
  6. print('Beginning file download attempts...')
  7.  
  8. var = 1
  9.  
  10. while var == 1:
  11. try:
  12. number = (random.randint(22000000,24000000))
  13. code = (random.randint(101000,199999))
  14. url = 'http://www.ugrad.math.ubc.ca/coursedoc/math103/2017W2/quiz/quiz1/quiz1-%s-%s.pdf' % (number, code)
  15. urllib.request.urlretrieve(url, '/Users/alirod/Desktop/Python/examen/examen.pdf')
  16. except urllib.error.HTTPError as e:
  17. if e.code in (..., 403, ...):
  18. # print ('===HTTP Error 403===')
  19. print (number)
  20. print (code)
  21. continue
  22. except http.client.HTTPException as e:
  23. print ('HTTP Client Error')
  24. continue
  25.  
  26. print ("End of Loop")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement