我正在尝试使用selenium从recaptcha音频源获取特定的属性。
然而,我不知道如何做到这一点。下面是来自https://www.google.com/recaptcha/api2/demo的一个示例
我想检索src链接并打印出来。
我想知道是否有什么方法可以让我使用selenium来做到这一点?
到目前为止,我的代码允许我加载到recaptcha演示页面->上,单击“我不是机器人”->点击音频按钮
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
PATH="C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("http://localhost/recaptcha-v2/")
# 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()
#This works, i can get the captcha token
# Src_URL = driver.find_element_by_id('recaptcha-token').get_attribute('value')
#This does not work, it can't locate the src
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "audio-source")))
Src_URL = driver.find_element_by_id('audio-source').get_attribute('src')
print(Src_URL)请指教谢谢!
发布于 2020-08-08 08:38:23
我使用下面的代码从src标记中提取audio属性(如果audio标记位于另一个iframe中,则更改iframe )-
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver import ActionChains
import time
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 5)
action = ActionChains(driver)
driver.get("YourURL")
# you can also use time.sleep(5)
wait.until(expected_conditions.presence_of_element_located((By.ID, "audio-source")))
Src_URL = driver.find_element_by_id('audio-source').get_attribute('src')
print(Src_URL)https://stackoverflow.com/questions/63304606
复制相似问题