python 如何使用selenium在heroku上保持浏览器会话10分钟?

oknrviil  于 2023-05-16  发布在  Python
关注(0)|答案(1)|浏览(93)

这是我使用的代码。我需要浏览器会话保持活跃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
vhipe2zx

vhipe2zx1#

我发现这很有用,也许对你有帮助。

selenium保持浏览器打开

options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')

如何保持webdriver标签页打开

options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')

** selenium 开放检查**

从selenium导入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:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("https://selenium.dev/documentation/en/")
print(driver.title)

来源:https://www.codegrepper.com/code-examples/python/selenium+keep+browser+open
谢谢祝您愉快。

相关问题