furas

Selenium - wait for download

Jul 29th, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. from selenium import webdriver
  2. import time
  3. import os
  4.  
  5. FOLDER = "/home/furas/Pulpit/" # for some folders it needs / at the end
  6. #FOLDER = "D:/Download"
  7.  
  8. options = webdriver.ChromeOptions()
  9. prefs = {"download.default_directory": FOLDER}
  10. options.add_experimental_option("prefs", prefs)
  11.  
  12. driver = webdriver.Chrome(chrome_options=options)
  13. driver.get('https://github.com/ageitgey/face_recognition')
  14.  
  15. button = driver.find_element_by_css_selector('summary.btn')
  16. button.click()
  17.  
  18. dbutton = driver.find_element_by_css_selector('a.get-repo-btn')
  19. dbutton.click()
  20.  
  21. time.sleep(0.5)
  22.  
  23. while True:
  24.     wait = False
  25.    
  26.     for i in os.listdir(FOLDER):
  27.         if ".crdownload" in i:
  28.             wait = True
  29.             break # no need to check other files
  30.        
  31.     if not wait:
  32.         break # exit `while True`
  33.    
  34.     print('wait')
  35.     time.sleep(0.5)
  36.  
  37. print("download complete")
Add Comment
Please, Sign In to add comment