简体   繁体   English

镀铬Canary的Splnter硒无头(python)

[英]Splnter selenium headless with Chrome Canary (python)

I can drive a headless browser using selenium and Chrome Canary. 我可以使用Selenium和Chrome Canary驱动无头浏览器。 But I can't get it to work using Splinter. 但是我无法使用Splinter使其工作。

Thanks in advance. 提前致谢。

Here's what works. 这是可行的。

import os  
from selenium import webdriver  
from selenium.webdriver.common.keys import Keys  
from selenium.webdriver.chrome.options import Options

chrome_options = Options()  
chrome_options.add_argument("--headless")  
chrome_options.binary_location = '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'   
driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',   chrome_options=chrome_options)

Here's what doesn't work: 这是行不通的:

from splinter import Browser
executable_path = {'executable_path':'/Applications/Google Chrome Canary/Contents/MacOS/Google Chrome Canary'}
B=Browser('chrome',**executable_path)

Incidentally Splinter DOES work with phantomjs 顺便说一句,Splinter确实与phantomjs一起工作

executable_path = {'executable_path':'/Applications/phantomjs/bin/phantomjs'}
 B=Browser('phantomjs',**executable_path )

The error message is 错误消息是

WebDriverException: Message: 'Google Chrome Canary' executable needs to be in PATH. WebDriverException:消息:“ Google Chrome Canary”可执行文件必须位于PATH中。 Please see https://sites.google.com/a/chromium.org/chromedriver/home 请参阅https://sites.google.com/a/chromium.org/chromedriver/home

Here's the path, as perceived by os.os.environ['PATH'] 这是os.os.environ['PATH']所感知os.os.environ['PATH']

/Users/jonschull-MBPR/miniconda2/bin:/Applications/Google Chrome Canary/Contents/MacOS/Google Chrome Canary:/Users/jonschull-MBPR/miniconda2/bin:/Users/jonschull-MBPR/anaconda/bin:/Users/jonschull-MBPR/Downloads/google-cloud-sdk/bin:/opt/local/bin:/opt/local/sbin:/Users/jonschull-MBPR/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/chromedrive:/opt/X11/bin:/usr/local/mongodb/bin

And by the way, I've tried escaping "Google\\ Chrome\\ Canary " 顺便说一句,我尝试转义“ Google \\ Chrome \\ Canary”

好吧,根据splitter git中的问题,您只需要升级到splinter 0.7.6+。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM