Jac*_*hin 17 python selenium webdriver selenium-chromedriver
所以有一个很好的长序列表可以传递给chromedriver.
我想特别使用它们中的一些--disable-logging
.
我不想(仅)在本地使用chromedriver,但我想编写我要使用的所有代码 webdriver.Remote()
.
这是我用来设置chrome驱动程序的代码,它适用于vanilla chrome实例.
driver = webdriver.Remote(
command_executor = 'http://127.0.0.1:4444/wd/hub',
desired_capabilities = {
'browserName': 'chrome',
}
)
Run Code Online (Sandbox Code Playgroud)
但是,我无法弄清楚如何传递其他选项.
当我看到时,driver.capabilities
我看到以下内容
{
u'rotatable': False,
u'browserConnectionEnabled': False,
u'acceptSslCerts': False,
u'cssSelectorsEnabled': True,
u'javascriptEnabled': True,
u'nativeEvents': True,
u'databaseEnabled': False,
u'chrome.chromedriverVersion': u'23.0.1240.0',
u'locationContextEnabled': False,
u'takesScreenshot': True,
u'platform': u'MAC',
u'browserName': u'chrome',
u'webdriver.remote.sessionid': u'1352096075502',
u'version': u'22.0.1229.94',
u'applicationCacheEnabled': False,
u'webStorageEnabled': True,
u'handlesAlerts': True,
u'chrome.nativeEvents': False
}
Run Code Online (Sandbox Code Playgroud)
我没有看到任何其他参数(除此之外desired_capabilities
)将参数传递给chromedriver webdriver.Remote
.这是真的?我错过了什么吗?还有其他一些定制chromedriver的策略吗?
在CromeDrive维基页面上有一个很好的例子,它显示了"使用特定标志启动Chromium",但所有示例都是针对webdriver.Chrome()
; 这个例子也在java中,所以它甚至可能不适用于python.
如果有人让这个工作或者可以告诉我这不起作用我会很感激.谢谢.
新问题
我不确定处理后续问题的最佳方法.
所以,我得到了我的问题的答案,但我仍然无法关闭日志记录.检查以下记录器行.
[0.455][INFO]: Launching chrome: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --enable-logging --log-level=1 --disable-hang-monitor --disable-prompt-on-repost --dom-automation --full-memory-crash-report --no-default-browser-check --no-first-run --disable-background-networking --disable-sync --disable-translate --disable-web-resources --safebrowsing-disable-auto-update --safebrowsing-disable-download-protection --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --use-mock-keychain --ignore-certificate-errors --disable-logging about:blank
Run Code Online (Sandbox Code Playgroud)
我可以将参数传递--disable-logging
给chromedriver但是它似乎关心的是第一个启用日志记录的参数.我想我需要找出保存Chrome新实例的默认参数的位置.
roo*_*oot 23
这应该给你可用的标志:
from selenium import webdriver
options = webdriver.ChromeOptions()
# set some options
# for example:
# options.add_argument('--disable-logging')
driver = webdriver.Remote(desired_capabilities=options.to_capabilities())
Run Code Online (Sandbox Code Playgroud)
小智 5
自从 selenium remote 和 chrome webdrivers 改变以来,我只花了两美分。
import os
from selenium import webdriver
class RemoteBrowser:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('whitelisted-ips')
chrome_options.add_argument('headless')
chrome_options.add_argument('no-sandbox')
chrome_options.add_argument('window-size=1200x800')
def __init__(self):
self.hub_url = os.environ['HUB_URL']
self.driver = webdriver.Remote(
command_executor='http://' + self.hub_url + '/wd/hub',
desired_capabilities = {'browserName': 'chrome'},
options=self.chrome_options
)
Run Code Online (Sandbox Code Playgroud)