Guest User

Untitled

a guest
Aug 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. def getIndivTrials(newDir):
  2. import os, urllib2, time, socket
  3.  
  4. failedAttempts = []
  5. #...
  6. #download the page
  7. socket.setdefaulttimeout(10)
  8.  
  9. try:
  10. response = urllib2.urlopen(url)
  11. webContent = response.read()
  12.  
  13. #create the filename and place it in the new "trials" directory
  14. filename = items + '.html'
  15. filePath = pjoin(newDir, filename)
  16.  
  17. #save the file
  18. f = open(filePath, 'w')
  19. f.write(webContent)
  20. f.close
  21. except:
  22. failedAttempts.append(url)
  23.  
  24. #pause for 3 seconds
  25. time.sleep(3)
  26.  
  27. print "the following files failed to download" + str(failedAttempts)
Add Comment
Please, Sign In to add comment