[Python] How to bypass cloudflare python using edge browser and selenium?

Discussão em 'Python' iniciado por Stack, Janeiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    I have not found anything on using edge browser for bypassing cloudflare. I am working with YouTube mp3 downloaders online such as https://yt1ss.pro/en199/youtube-to-mp3. Whenever I boot up selenium it shows cloudflare saying 'verifying'. Then it says 'Error'. I take it that it senses that I am using selenium. I was wanting it to go through and click through all the buttons to download the video. I have also been using pytubefix to download videos but some URLs (https://music.youtube.com/watch?v=OwONpOi6RYE) don't work with pytubefix. I get this error: pytubefix.exceptions.VideoUnavailable: OwONpOi6RYE is unavailable

    If they did not work there, then it would try the online downloader.

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.edge.options import Options

    import time

    options = Options()
    options.add_argument("--disable-blink-features=AutomationControlled") #I am not exactly sure what this does. I read somewhere that it could help hide the bot fingerprint.
    driver = webdriver.Edge(options=options)
    driver.get('https://yt1ss.pro/en199/youtube-to-mp3')

    url = 'https://music.youtube.com/watch?v=OwONpOi6RYE'


    driver.find_element(By.XPATH, '//*[@id="txt-url"]').send_keys(url)
    driver.find_element(By.XPATH, '//*[@id="btn-submit"]').click()
    driver.implicitly_wait(5)
    driver.find_element(By.XPATH, '//*[@id="mp4"]/table/tbody/tr[2]/td[3]/button').click()
    driver.implicitly_wait(5)
    driver.find_element(By.XPATH, '//*[@id="A_downloadUrl"]').click()


    I have tried other downloaders that don't have cloudflare but they still don't work. They have pop up ads. I have also tried headless selenium and looked at cloudscraper (https://pypi.org/project/cloudscraper/) although not sure how this would work with selenium.

    Any help would be appreciated.

    Continue reading...

Compartilhe esta Página