Python selenium-webdriver 服务器关闭后, webdriver 不可用

2019-09-13 11:12:27 +08:00
 DOUWH

最近使用到 selenium 做一些数据采集,想放到服务器上后台运行,结果出现了一些错误!还请大佬们来指点!

问题描述: nohup 后台运行 python,退出服务器,selenium 跟着也退出了 selenium.common.exceptions.WebDriverException: Message: chrome not reachable (Session info: headless chrome=77.0.3865.75)

运行命令:nohup python -u python.py > run.log 2>&1 &
selenium-webdriver 启动代码:
	service = Service('/home/chromedriver')
	service.command_line_args()
	service.start()
	options = webdriver.ChromeOptions()
	options.add_argument('--headless')
	options.add_argument('--no-sandbox')
	options.add_argument('--disable-dev-shm-usage')
	options.add_argument('--disable-gpu')
	prefs = {"profile.managed_default_content_settings.images": 2}
	options.add_experimental_option("prefs", prefs)
	driver = webdriver.Chrome(options=options)

还请各位大佬看下问题出在哪里。

2842 次点击
所在节点    Python
3 条回复
hfutzj
2019-09-13 11:16:38 +08:00
服务器后台运行的我一般用 screen
ysc3839
2019-09-13 11:18:28 +08:00
建议使用 screen 或 tmux。
DOUWH
2019-09-13 11:22:22 +08:00
@hfutzj
@ysc3839

好的两位大哥,我尝试一下

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/600600

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX