1

I'm trying to extract a table from html using selenium. My intention is capture the all class "iframe-b3", because I need the date and the values in the table.

https://www.b3.com.br/pt_br/market-data-e-indices/servicos-de-dados/market-data/consultas/boletim-diario/boletim-diario-do-mercado/

"Tabela: Participação dos Investidores" Code trials:

driver.find_element(by=By.CLASS_NAME, value="iframe-b3")
print_tabela = driver.find_element(by=By.CLASS_NAME, value="iframe-b3")

I need to copy this informations and transcript to Excel.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
f_pro_97
  • 13
  • 2

1 Answers1

0

I don't find the table on the website. However the datepicker element is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired presence_of_element_located.

  • You can use either of the following locator strategies:

    • Using CSS_SELECTOR:

      driver.get('https://www.b3.com.br/pt_br/market-data-e-indices/servicos-de-dados/market-data/consultas/boletim-diario/boletim-diario-do-mercado/')
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#onetrust-accept-btn-handler"))).click()
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.iframe-b3")))
      print(WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "div.duet-date input[name='date']"))).get_attribute("value"))
      driver.quit()
      
  • Console Output:

    2023-02-07
    
  • Note : You have to add the following imports :

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

Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352