嗨,我有一个脚本可以根据过滤器抓取网站,在最新的 chrome 更新和 chromedriver 更新之前一直运行良好,然后其中一个过滤器无法点击。
我有一个重复 10 次的 try and except 循环,有时这有时就足够了,有时我需要 > 15 次点击同一行代码才能最终工作。
这是我启动网页的代码:
from selenium import webdriver
url='https://www.marketscreener.com/stock-exchange/calendar/finance/'
options=webdriver.ChromeOptions()
chrome_prefs = {}
options.experimental_options["prefs"]=chrome_prefs
chrome_prefs["profile.defaul_content_settings"] = {"popups":1}
options.add_argument('--disable-browser-side-navigation')
options.add_argument('--disable-infobars')
options.add_argument('--disable-extensions')
options.add_argument('--disable-popup-blocking')
options.add_argument('--disable-notifications')
driver = webdriver.Chrome(executable_path=r'foo.exe',options=options)
使用我的凭据登录后,我尝试使用以下代码行:
driver.find_element_by_id("selCountry").click()
这会打开国家/地区过滤器下拉菜单。大多数情况下,它需要任意数量 >10 次尝试才能最终起作用。
我正在使用 chrome 版本 87.0.4280.141 及其带有 python 3.7 的 chromedriver。
谁能为我的问题提供更好的解决方案,或者解释为什么在 x 次尝试后它会成功?