这是我使用的代码。我需要浏览器会话保持10分钟。
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")
s = Service(executable_path=os.environ.get("CHROMEDRIVER_PATH"))
driver = webdriver.Chrome(service=s, options=chrome_options)
driver.get(URL)
button = driver.find_element(by=By.XPATH,value='XPATH')
button.click()
time.sleep(600)
driver.quit()
这是我在日志中看到的
2022-05-16T15:06:47.277256+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2022-05-16T15:06:48.362371+00:00 heroku[web.1]: Process exited with status 137
2022-05-16T15:06:47.953605+00:00 heroku[web.1]: Stopping process with SIGKILL
2022-05-16T15:06:48.465543+00:00 heroku[web.1]: State changed from starting to crashed
我发现这很有用,也许对你会有帮助。
硒保持浏览器打开
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:WebDriverschromedriver.exe')
如何保持webdriver选项卡打开
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=options, executable_path=r'C:WebDriverschromedriver.exe')
selenium open inspect
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument("--auto-open-devtools-for-tabs")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:UtilityBrowserDriverschromedriver.exe')
driver.get("https://selenium.dev/documentation/en/")
print(driver.title)
来源:https://www.codegrepper.com/code-examples/python/selenium +坚持+浏览器+开放
谢谢你,祝你今天愉快。