0
 driver.get "https://www.ambito.com/contenidos/dolar.html"

I want to stop loading after a determined amount of time or once I've got the elements that I need. I tried lots of things, but "driver.get" doesn't end unless the page is fully loaded or if I stop it manually.

Anyone knows?

2
  • Update the question with your code attempts. Commented Sep 4 at 0:16
  • Stop being an automaton, please Commented Sep 13 at 19:14

1 Answer 1

0

I see the particular site you've mentioned takes a long loading time, while many of the DOM elements are already visible/loaded.

My suggestion to you would be to use a Page Load Strategy

You can tell Selenium not to wait for the whole document to be fully loaded:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.page_load_strategy = 'eager'   # or 'none'
driver = webdriver.Chrome(options=options)

driver.get("https://www.ambito.com/contenidos/dolar.html")

Here are the available page loading strategies:

  • "normal" (default): waits for full load.

  • "eager": waits only until DOMContentLoaded or a certain element.

  • "none": returns immediately after the first bytes arrive.

This website uses Cloudflare Human verification, so I would suggest using SeleniumBase , a wrapper around Selenium that can take care of it.

Here's a working example:

from seleniumbase import SB

url = "https://www.ambito.com/contenidos/dolar.html"


with SB(uc=True, page_load_strategy="eager", test=True) as sb:
    sb.maximize_window()
    sb.activate_cdp_mode(url)
    sb.uc_gui_click_captcha()  # handles potential CAPTCHA

    nav_tab = sb.wait_for_element("nav.main-nav", timeout=5)
    print(nav_tab.text.split())

output:

['Dólar', 'Economía', 'Finanzas', 'Política', 'Negocios', 'Opinión', 'Uruguay']

for example, in code above, if you just want to extract or test for the navigation bar element (nav.main-nav) to appear in DOM and close the browser right after that without waiting ages until the browser fully loads.

Sign up to request clarification or add additional context in comments.

1 Comment

The problem is that none of this applies to VBA, which is a requirement of the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.