Firefox 和 Chrome 无头模式无法在 VPS(Ubuntu 18.04 LTS)上使用 Python/Selenium

Firefox 和 Chrome 无头模式无法在 VPS(Ubuntu 18.04 LTS)上使用 Python/Selenium

我正在尝试使用 Python 让 Chrome 以无头模式运行,但出于某种原因,无论我尝试阅读什么网站,都只会得到一个空白页。

谷歌浏览器:第 77 章

Chrome 驱动程序:最新版本(也尝试过旧版本)

操作系统:Ubuntu 18.04.3 LTS(虚拟服务器)

经过几个小时的研究,我发现了几个类似的问题和许多不同的解决方案,但这些解决方案都没有帮助我。

我在本地机器上尝试了具有相同选项的脚本,脚本运行没有任何问题。

Python代码:

options = Options()
options.add_argument('--remote-debugging-port=9555')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
options.add_argument('--allow-insecure-localhost')
options.add_argument('--allow-running-insecure-content')
options.add_argument('--disable-extensions')
options.add_argument('--start-maximized')
options.binary_location = "/usr/bin/google-chrome-beta"

driver = webdriver.Chrome(options=options)

driver.get("https://www.google.de")

driver.save_screenshot('picture.png')
print(driver.page_source.encode('utf-8'))

我也尝试使用 geckodriver 切换到 Firefox,但没有成功。

火狐:68、69、70(每晚)

壁虎驱动程序:0.24 和 0.23

(使用不同的 Firefox/geckodriver 版本组合进行测试)

这里是 geckodriver 的日志:

1566393297399   mozrunner::runner   INFO    Running command: "/usr/bin/firefox-trunk" "-marionette" "--headless" "--width=1920" "--height=1200" "--allow-insecure-localhost" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileFeIeHY"

 *** You are running in headless mode.

 1566393298482  [email protected] WARN    Loading extension '[email protected]': Reading manifest: Invalid extension permission: mozillaAddons
 1566393298482  [email protected] WARN    Loading extension '[email protected]': Reading manifest: Invalid extension permission: telemetry
 1566393298483  [email protected] WARN    Loading extension '[email protected]': Reading manifest: Invalid extension permission: resource://pdf.js/
 1566393298483  [email protected] WARN    Loading extension '[email protected]': Reading manifest: Invalid extension permission: about:reader*

 [Parent 2681, Gecko_IOThread] WARNING: pipe error: Datenübergabe unterbrochen (broken pipe): file /build/firefox-trunk-Wppa8r/firefox-trunk-70.0~a1~hg20190819r488674/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 728
 [Parent 2681, Gecko_IOThread] WARNING: FileDescriptorSet destroyed with unconsumed descriptors: file /build/firefox-trunk-Wppa8r/firefox-trunk-70.0~a1~hg20190819r488674/ipc/chromium/src/chrome/common/file_descriptor_set_posix.cc, line 23
 [Parent 2681, Gecko_IOThread] WARNING: FileDescriptorSet destroyed with unconsumed descriptors: file /build/firefox-trunk-Wppa8r/firefox-trunk-70.0~a1~hg20190819r488674/ipc/chromium/src/chrome/common/file_descriptor_set_posix.cc, line 23
 [Parent 2681, Gecko_IOThread] WARNING: FileDescriptorSet destroyed with unconsumed descriptors: file /build/firefox-trunk-Wppa8r/firefox-trunk-70.0~a1~hg20190819r488674/ipc/chromium/src/chrome/common/file_descriptor_set_posix.cc, line 23
 [Parent 2681, Gecko_IOThread] WARNING: FileDescriptorSet destroyed with unconsumed descriptors: file /build/firefox-trunk-Wppa8r/firefox-trunk-70.0~a1~hg20190819r488674/ipc/chromium/src/chrome/common/file_descriptor_set_posix.cc, line 23
 [Parent 2681, Gecko_IOThread] WARNING: FileDescriptorSet destroyed with unconsumed descriptors: file /build/firefox-trunk-Wppa8r/firefox-trunk-70.0~a1~hg20190819r488674/ipc/chromium/src/chrome/common/file_descriptor_set_posix.cc, line 23
 [Parent 2681, Gecko_IOThread] WARNING: FileDescriptorSet destroyed with unconsumed descriptors: file /build/firefox-trunk-Wppa8r/firefox-trunk-70.0~a1~hg20190819r488674/ipc/chromium/src/chrome/common/file_descriptor_set_posix.cc, line 23
 [Parent 2681, Gecko_IOThread] WARNING: pipe error (119): Die Verbindung wurde vom Kommunikationspartner zurückgesetzt: file /build/firefox-trunk-Wppa8r/firefox-trunk-70.0~a1~hg20190819r488674/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 358
 [Parent 2681, Gecko_IOThread] WARNING: pipe error (121): Die Verbindung wurde vom Kommunikationspartner zurückgesetzt: file /build/firefox-trunk-Wppa8r/firefox-trunk-70.0~a1~hg20190819r488674/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 358
 [Parent 2681, Gecko_IOThread] WARNING: pipe error (123): Die Verbindung wurde vom Kommunikationspartner zurückgesetzt: file /build/firefox-trunk-Wppa8r/firefox-trunk-70.0~a1~hg20190819r488674/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 358
 [Parent 2681, Gecko_IOThread] WARNING: pipe error (124): Die Verbindung wurde vom Kommunikationspartner zurückgesetzt: file /build/firefox-trunk-Wppa8r/firefox-trunk-70.0~a1~hg20190819r488674/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 358
 [Parent 2681, Gecko_IOThread] WARNING: pipe error (130): Die Verbindung wurde vom Kommunikationspartner zurückgesetzt: file /build/firefox-trunk-Wppa8r/firefox-trunk-70.0~a1~hg20190819r488674/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 358

 ###!!! [Parent][MessageChannel] Error: (msgtype=0x37001A,name=PContent::Msg_RegisterChromeItem) Channel error: cannot send/recv

 A content process crashed and MOZ_CRASHREPORTER_SHUTDOWN is set, shutting down

 JavaScript error: resource://activity-stream/lib/ActivityStreamPrefs.jsm, line 27: NS_ERROR_ILLEGAL_VALUE: Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIPrefBranch.removeObserver]
 ERROR 2019-08-21T13:15:04Z: xulstore::persist: error creating XULStore thread: NS_ERROR_OUT_OF_MEMORY
 JavaScript error: resource://gre/modules/XULStore.jsm, line 70: NS_ERROR_NOT_AVAILABLE: Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXULStore.setValue]
 1566393304745  addons.xpi-utils    WARN    Error: XPI database modified after shutdown began(resource://gre/modules/addons/XPIDatabase.jsm:1483:17) JS Stack trace: saveChan

 [email protected]:1483:17
 [email protected]:2285:10
 [email protected]:2213:12
 [email protected]:4344:27
 [email protected]:4371:14
 async*[email protected]:4297:16
 async*XPIProvider[meth]@XPIProvider.jsm:3110:28
 [email protected]:2588:7
 [email protected]:4071:33
 [email protected]:1151:28
 [email protected]:1110:20
 async*[email protected]:743:18
 async*[email protected]:2010:18
 [email protected]:2633:16
 [email protected]:4442:21
 [email protected]:2042:19
 EventListener.handleEvent*[email protected]:1898:12
 EventHandlerNonNull*@browser.xhtml:118:39
 1566393304746  addons.xpi-utils    WARN    Error: XPI database modified after shutdown began(resource://gre/modules/addons/XPIDatabase.jsm:1483:17) JS        Stack trace: [email protected]:1483:17
 [email protected]:2216:10
 [email protected]:4344:27
 [email protected]:4371:14
 async*[email protected]:4297:16
 async*XPIProvider[meth]@XPIProvider.jsm:3110:28
 [email protected]:2588:7
 [email protected]:4071:33
 [email protected]:1151:28
 [email protected]:1110:20
 async*[email protected]:743:18
 async*[email protected]:2010:18
 [email protected]:2633:16
 [email protected]:4442:21
 [email protected]:2042:19

 JavaScript error: resource://gre/modules/UrlClassifierListManager.jsm, line 602: NS_ERROR_NOT_AVAILABLE: Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIUrlClassifierStreamUpdater.downloadUpdates

 1566393304895  Marionette  INFO    Listening on port 37073
 JavaScript error: resource://gre/modules/JSONFile.jsm, line 173: Error: Data is not ready.
 console.log: "RemoteSettingsWorker error: UnknownError: The operation failed for reasons unrelated to the database itself and not covered by any other error code."

 ###!!! [Parent][DispatchAsyncMessage] Error: PBackgroundIDBFactory::Msg_PBackgroundIDBFactoryRequestConstructor Value error: message was deserialized, but contained an illegal value

 JavaScript error: chrome://marionette/content/server.js, line 105: NS_ERROR_NOT_INITIALIZED: Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIServerSocket.close]

我也在我的本地机器(Arch Linux)上测试了它,它运行正常,没有任何问题。几乎可以肯定我尝试了所有能在网上找到的方法。任何想法或建议(Firefox 或 Chrome)都将不胜感激。

我已经在考虑在服务器上从 Ubuntu 切换到 CentOS,但想先再试一次。

相关内容