没有selenium或xvfb的Firefox headless运行一个简单的javascrip

2024-06-16 10:27:50 发布

您现在位置:Python中文网/ 问答频道 /正文

具体来说,我对运行selenium、phantomjs、chrome或任何类型的虚拟帧缓冲区(如xvfb)不感兴趣。在

尽可能通过v56:

firefox -headless

是否可以运行一些简单的操作:

^{pr2}$

不管什么时候。。。一些.js公司名称:

location.href="https://stackoverflow.com"
console.log(document.body);

除了查看https://github.com/saucelabs/foxdriver的源代码,我还没有找到一个关于控制它的好答案:

➜  /Users/jmunsch/Desktop/public_dev /Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin -headless 'javascript:location.href="https://ebay.com"'
*** You are running in headless mode.
[OSVR] Failed to load OSVR Util library!
[OSVR] Failed to load OSVR Util library!
2017-12-13 18:25:23.147 plugin-container[81081:12271051] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0xb93b, name = 'com.apple.tsm.portname'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2017-12-13 18:25:23.148 plugin-container[81081:12271051] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0xbc03, name = 'com.apple.CFPasteboardClient'
See /usr/include/servers/bootstrap_defs.h for the error codes.
1513218323615   addons.webextension.jid1-ZAdIEUB7XOzOJw@jetpack WARN    Please specify whether you want browser_style or not in your browser_action options.
Extension error: TypeError: tab.url is undefined moz-extension://73977042-24a6-4741-8f43-9c6dc9c5677e/js/tabManager.js 96
[[Exception stack
@moz-extension://73977042-24a6-4741-8f43-9c6dc9c5677e/js/tabManager.js:96:1
Current stack
runSafeSyncWithoutClone@resource://gre/modules/ExtensionUtils.jsm:63:129
runSafeWithoutClone@resource://gre/modules/ExtensionCommon.jsm:174:38
fire@resource://gre/modules/ExtensionChild.jsm:763:71
receiveMessage@resource://gre/modules/ExtensionChild.jsm:765:76
_callHandlers/<@resource://gre/modules/MessageChannel.jsm:587:17
_callHandlers@resource://gre/modules/MessageChannel.jsm:586:14
_handleMessage/deferred.promise<@resource://gre/modules/MessageChannel.jsm:651:7
_handleMessage@resource://gre/modules/MessageChannel.jsm:648:24
receiveMessage@resource://gre/modules/MessageChannel.jsm:163:5
]]
^C** Unknown exception behavior: -2147483647

FF版本:

➜  /Users/jmunsch/Desktop/public_dev  /Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin  --version
Mozilla Firefox 56.0a1

看起来我必须为json解析流套接字,是否有异步pythonic版本来执行此操作:


Tags: toinhttpscommodulesjserrorfirefox