admin管理员组

文章数量:1320661

I have not found anything on using edge browser for bypassing cloudflare. I am working with YouTube mp3 downloaders online such as . 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 () 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.webdrivermon.by import By
from selenium.webdrivermon.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('')

url = ''


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 (/) although not sure how this would work with selenium.

Any help would be appreciated.

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/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.webdrivermon.by import By
from selenium.webdrivermon.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/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./project/cloudscraper/) although not sure how this would work with selenium.

Any help would be appreciated.

Share Improve this question asked Jan 18 at 16:38 MeFunyMeFuny 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default -1

Well, you can use 2captcha-python turnstile solver and API endpoint request to yt1ss.

Update 2captcha API

import sys
import os

try:
    from rich import print
    from twocaptcha import TwoCaptcha
    import requests
except ImportError:
    os.system("pip3 install requests rich 2captcha-python -U")
    from rich import print
    from twocaptcha import TwoCaptcha
    import requests


def get_captcha_token():
    """Fetch CAPTCHA token using 2Captcha service."""
    solver = TwoCaptcha(CAPTCHA_API_KEY)
    try:
        result = solver.turnstile(sitekey=CAPTCHA_SITE_KEY, url=CAPTCHA_URL)
        return result["code"]
    except Exception as e:
        print(f">= Error solving CAPTCHA: {e}")
        return None


def fetch_mp3_conversion(CAPTCHA_URL, MUSIC_URL):
    """Fetch MP3 conversion data from yt1ss.pro."""
    captcha_token = get_captcha_token()
    if not captcha_token:
        print(">= Failed to solve CAPTCHA.")
        return None

    headers = {
        "accept": "application/json, text/javascript, */*; q=0.01",
        "accept-language": "en-US,en;q=0.9",
        "cache-control": "no-cache",
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "pragma": "no-cache",
        "priority": "u=1, i",
        "referer": CAPTCHA_URL,
        "sec-ch-ua": '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": '"Windows"',
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
        "x-requested-with": "XMLHttpRequest",
    }

    params = {
        "retry": "undefined",
        "platform": "youtube",
        "mhash": "d503358d68f14ea7",
    }

    data = {
        "url": MUSIC_URL,
        "ajax": "1",
        "lang": "en",
        "cftoken": captcha_token,
    }

    try:
        response = requests.post(
            "https://yt1ss.pro/mates/en/analyze/ajax",
            params=params,
            headers=headers,
            data=data,
        )
        response.raise_for_status()
        return response.json()
    except Exception as e:
        print(f">= Error making request: {e}")
        return None


if __name__ == "__main__":

    root_path = os.path.dirname(os.path.abspath(__file__))
    os.chdir(root_path)

    CAPTCHA_API_KEY = os.getenv("APIKEY_2CAPTCHA", "YOUR_API_KEY")
    CAPTCHA_SITE_KEY = "0x4AAAAAAA2BcqfnaNPkn4HG"
    CAPTCHA_URL = "https://yt1ss.pro/en199/youtube-to-mp3"
    MUSIC_URL = "https://music.youtube/watch?v=OwONpOi6RYE"

    result = fetch_mp3_conversion(CAPTCHA_URL, MUSIC_URL)
    if result:
        print("Conversion result:", result)
    else:
        print("Failed to fetch conversion data.")

本文标签: How to bypass cloudflare python using edge browser and seleniumStack Overflow