我正在尝试使用selenium库编写Python脚本,单击此网页上的“Consultar”按钮https://www.anbima.com.br/pt_br/informar/taxas-de-titulos-publicos.htm。当我在浏览器中打开该按钮时,该按钮会出现在 html 代码中;但是,当我尝试使用 python 执行此操作时,它给了我另一个没有此按钮的 html 代码(即使使用动态内容)。你能帮我吗?该网站对任何人开放,所以你可以自己尝试一下。
什么都试过了!!所有用于处理 HTML 的库
这里是 selenium-python 代码(带解释),点击 Consultar 按钮。
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.anbima.com.br/pt_br/informar/taxas-de-titulos-publicos.htm")
wait = WebDriverWait(driver, 10)
# Below line will click on 'Prosseguir' cookie button. Use this code only if you are getting the cookie pop-up
wait.until(EC.element_to_be_clickable((By.ID, "LGPD_ANBIMA_global_sites__text__btn"))).click()
# Below line of code will switch driver context into the IFRAME
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[@class='full']")))
# Below line will click on the targeted button
wait.until(EC.element_to_be_clickable((By.XPATH, "//img[@name='Consultar']"))).click()
# Below line will come out of IFRAME
driver.switch_to.default_content()
time.sleep(10)