0

Hello, I Have Automatic Downloading Python Script:

Below is the CODE:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


links = [
'https://www.youtube.com/watch?v=AqCXX1ZK9bo'

]

for link in links:
    browser=webdriver.Chrome(r'C:\Users\\Downloads\chromedriver')
    browser.get('https://www.onlinevideoconverter.com/pt/youtube-converter')


    ak=browser.find_element_by_id('texturl')
    ak.send_keys(link)

    au = WebDriverWait(browser, 40).until(EC.element_to_be_clickable((By.XPATH, '//*[text() = "Começar"]')) )
    au.click()
    time.sleep(5)
    af = WebDriverWait(browser, 90).until(
    EC.presence_of_element_located((By.ID, 'downloadq'))
)

    browser.execute_script('arguments[0].click();', af) 

When and activating the

af = WebDriverWait(browser, 90).until(
        EC.presence_of_element_located((By.ID, 'downloadq'))
    )

        browser.execute_script('arguments[0].click();', af) 

And Generated a Download in the Chrome bar. And My Goal is that When the Download reaches 100% the Tab will automatically close with a browser.close

What is missing?

Pakito
  • 1
  • don't you get error message when you run it in console/terminal/cmd.exe ? I get some error when I run your code. – furas Dec 06 '19 at 17:00
  • Error No, But Changed to Your Webdriver Directory? – Pakito Dec 06 '19 at 17:02
  • it is strange because you forgot to `import time` – furas Dec 06 '19 at 17:05
  • It is missing Because it was a down but can disregard it was needing to close the page with the download reach 100% – Pakito Dec 06 '19 at 17:07
  • always put working code - don't expect that will correcting mistakes like this. – furas Dec 06 '19 at 17:09
  • as I know Selenium gives access to displayed page but not to other elements in browser so you can only check in folder if file was downloaded - [python selenium, find out when a download has completed?](https://stackoverflow.com/questions/34338897/python-selenium-find-out-when-a-download-has-completed) or you can use other modules to download it and then you can close widow at once. – furas Dec 06 '19 at 17:11
  • and you would tell me how I change the standard directories of the downloads – Pakito Dec 06 '19 at 17:15
  • always use Google before ask: [Selenium Webdriver in Python - files download directory change in Chrome preferences](https://stackoverflow.com/questions/18026391/selenium-webdriver-in-python-files-download-directory-change-in-chrome-prefere) – furas Dec 06 '19 at 17:18

1 Answers1

1

Well I guess the easiest approach will be not to click the download button but to get the download link and then you can simply use urllib.retrieve() function to get the video downloaded locally in your system.

I guess this would be the best approach. Hope this helps :)

Debdut Goswami
  • 1,301
  • 12
  • 28
  • But I Need to See the Process Getting there I need to close each tab when it reaches 100% .but thanks – Pakito Dec 06 '19 at 17:11
  • I can give you another solution to close the chrome tab but that would be very unrealistic approach. You can use PyAutoGUI. Go to the following link: https://pyautogui.readthedocs.io/en/latest/introduction.html#examples Mainly this can be used to find gui items on screen, here `100%` and when it finds `100%` you can close the chrome tab in the same manner. – Debdut Goswami Dec 06 '19 at 17:14