我一直在尝试使用selenium搜索机场列表,以便能够从我使用tab访问的网站获取信息。每次当广告没有出现在网页上时,它都会起作用。我花了一点时间试图解决这个问题,但似乎没有任何效果。这是我的代码的一小部分,你们可以理解我在做什么:
driver = webdriver.Chrome()
driver.get("https://www.google.com")
a = driver.find_element_by_css_selector(".gLFyf")
a.clear()
a.send_keys(f'site:airnav.com/airport airnav {a[i]} {b[i]}')
print(f'airnav {a[i]} {b[i]}')
a.send_keys(Keys.RETURN)
actions = ActionChains(driver)
actions1 = actions.send_keys(Keys.TAB*19)
actions1.perform()
time.sleep(3)
actions = ActionChains(driver)
actions2 = actions.send_keys(Keys.ENTER)
actions2.perform()
act = driver.current_url
driver = webdriver.Chrome()
driver.get(f'https://web.archive.org/web/2015/{act}')
time.sleep(3)
a和b是列表,我用谷歌搜索这些列表中的每一个元素,并访问同一个网站。唯一让TAB方法停止工作的是,每当我尝试这个方法时,这些广告就会持续出现
禁用Chrome中的弹出窗口
对于Chrome,默认情况下会启用弹出窗口,即默认情况下禁用弹出窗口阻止程序。要启用弹出窗口阻止程序,即阻止弹出窗口,请在chromeOptions功能的ExcludeSwitchs下传递disable popup blocking参数,如下所示:
代码:
相关问题 更多 >
编程相关推荐