我尝试访问音频验证码。所以我用硒webdriver。但我不明白如何设置webdriver等待正确。当我启动代码时,似乎webdriver不会等待任何时间。 我设置错了什么?
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent
##proxy = "113.160.218.14:54432" # IP:PORT or HOST:PORT
proxies = ['94.79.52.207:8080', '5.45.64.97:3128', '46.105.190.36:3128',
'45.224.129.169:8080', '168.11.14.250:8009']
proxy = random.choice(proxies)
ua = UserAgent()
userAgent = ua.random
print(userAgent)
chromedriver = 'chromedriver'
os.environ['webdriver.chrome.driver'] = chromedriver
options = webdriver.ChromeOptions()
options.add_argument('start-maximized')
options.add_argument('--proxy-server=%s' % proxy)
options.add_argument(f'user-agent={userAgent}')
chrome_options = webdriver.ChromeOptions()
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chrome_options)
driver.delete_all_cookies()
driver.get('https://www.inipec.gov.it/cerca-pec/-/pecs/companies')
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']")))
WebDriverWait(driver, 40).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='recaptcha-checkbox goog-inline-block recaptcha-checkbox-unchecked rc-anchor-checkbox']/div[@class='recaptcha-checkbox-checkmark']"))).click()
driver.switch_to.default_content()
WebDriverWait(driver, 40).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@title='recaptcha challenge']")))
WebDriverWait(driver, 40).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="recaptcha-audio-button"]'))).click()