试图找出如何阻止我的浏览器完全加载(因为我需要的内容是首先要加载的东西之一)。换句话说,让浏览器打开,等待3秒,然后程序在浏览器中按下停止,这样"search_5Hours“才能尽快进行。
s = Service(r"C:\Users\Tim\Desktop\Forex\geckodriver.exe")
driver = webdriver.Firefox(service=s)
driver.get(LINK)
time.sleep(3) # Doesn't need to be 3 seconds
1. Tried this -> webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
2. Tried this -> driver.execute_script("window.stop()")
3. Tried this -> driver.find_element(by=By.TAG_NAME, value="body").send_keys("Keys.ESCAPE")
search_5Hours = driver.find_element(by=By.LINK_TEXT, value="5 Hours")
第三条似乎是最合理的选择,例如。一旦找到身体就停止(我认为这是加载的第一个元素)。
发布于 2022-04-21 12:16:40
一旦找到调用Window.stop()
的元素,就会在当前浏览上下文中停止进一步的资源加载,这相当于浏览器中的停止按钮。
driver.execute_script("window.stop();")
https://stackoverflow.com/questions/71953264
复制相似问题