ReCaptcha下载音频文件? [英] ReCaptcha download audio file?

查看:83
本文介绍了ReCaptcha下载音频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请让我知道我做错了什么

使用以下代码:


我在附近的元素上尝试了以下操作以获得其href值,并且它起作用了,我唯一的问题是上面的内容:

  src = WebDriverWait(driver,10).until(EC.element_to_be_clickable((通过CSS_SELECTOR,"a.rc-audiochallenge-tdownload-link"))).textsrc = src.get_attribute('href')打印(src) 

它处理的元素是:


我也尝试过:

  src = WebDriverWait(driver,10).until(EC.invisibility_of_element((By.XPATH,"//* [@ id = \" audio-source \]"))))src = src.get_attribute('src') 

但是我得到一个错误:

  src = src.get_attribute('src') 

AttributeError:布尔"对象没有属性"get_attribute"

解决方案

  WebDriverWait(driver,10).until(EC.element_to_be_clickable((通过CSS_SELECTOR,"span#recaptcha-anchor"))).click()driver.switch_to.default_content()WebDriverWait(驱动程序,10).until(EC.frame_to_be_available_and_switch_to_it((通过CSS_SELECTOR,"iframe [title ='recaptcha挑战']"))))WebDriverWait(驱动程序,10).until(EC.element_to_be_clickable((由CSS_SELECTOR,"button#recaptcha-audio-button")))).click()WebDriverWait(驱动程序,10).until(EC.presence_of_element_located((由CSS_SELECTOR,.rc-audiochallenge-play-button button"))))#获取mp3音频文件src = driver.find_element_by_id(音频源").get_attribute("src")打印(src) 

只需再为.rc-audiochallenge-play-button按钮添加一点

要下载,您应该使用:

 导入urllib.requesturllib.request.urlretrieve(src,"src.mp3") 

Please let me know of what I'm doing wrong

Using the code from: How to interact with the reCAPTCHA audio element using Selenium and Python

I want next to get the src file for the audio to download it, so I wrote exactly after the end of the provided code the following:

# get the mp3 audio file
src = driver.find_element_by_id("audio-source").get_attribute("src")

But Python returns run time error saying:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="audio-source"]"}
  (Session info: chrome=88.0.4324.96)

Note: I copied that code as is, and only added the last line

For your convince here is my full code:

def tmp():
    from selenium.webdriver.common.keys import Keys

    # recaptcha libraries
    import speech_recognition as sr
    import urllib
    # import pydub

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

    options = webdriver.ChromeOptions()
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path='/Users/ahmad/Desktop/chromedriver')
    driver.get("https://www.google.com/recaptcha/api2/demo")
    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(
        (By.CSS_SELECTOR, "iframe[src^='https://www.google.com/recaptcha/api2/anchor']")))
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span#recaptcha-anchor"))).click()
    driver.switch_to.default_content()
    WebDriverWait(driver, 10).until(
        EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[title='recaptcha challenge']")))
    WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.CSS_SELECTOR, "button#recaptcha-audio-button"))).click()

    # get the mp3 audio file
    src = driver.find_element_by_id("audio-source").get_attribute("src")


I tried on nearby element the following to get it's href value and it worked, my only problem is with what is above:

src=WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, "a.rc-audiochallenge-tdownload-link"))).text

src=src.get_attribute('href')

print(src)

the element it worked on was:


I tried this too:

src=WebDriverWait(driver, 10).until(
    EC.invisibility_of_element((By.XPATH, "//*[@id=\"audio-source\"]")))

src=src.get_attribute('src')

But I get an error:

src=src.get_attribute('src')

AttributeError: 'bool' object has no attribute 'get_attribute'

解决方案

WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
    (By.CSS_SELECTOR, "span#recaptcha-anchor"))).click()
driver.switch_to.default_content()
WebDriverWait(driver, 10).until(
    EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[title='recaptcha challenge']")))
WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, "button#recaptcha-audio-button"))).click()
WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CSS_SELECTOR, ".rc-audiochallenge-play-button button")))

# get the mp3 audio file

src = driver.find_element_by_id("audio-source").get_attribute("src")
print(src)

Just add one more wiat for the .rc-audiochallenge-play-button button

to download you should use:

import urllib.request
urllib.request.urlretrieve(src, "src.mp3")

这篇关于ReCaptcha下载音频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆