Python3,Selenium和Chrome便携式 [英] Python3, Selenium and Chrome portable
问题描述
可能有人可以帮助Windows,Python,Selenium以及将Chrome webdriver与ChromePortable结合使用.
probably someone can help with Windows, Python, Selenium and using Chrome webdriver with ChromePortable.
我已经定义了一个新文件夹
I've defined a new folder
c:\ myproject
c:\myproject
wedriver位于此文件夹中: c:\ myproject \ driver \ chromedriver.exe
Wihtin this folder the wedriver is located: c:\myproject\driver\chromedriver.exe
以及Chrome便携式
and also the Chrome Portable
c:\ myproject \ chromeportable \ chrome.exe
c:\myproject\chromeportable\chrome.exe
现在,我想构建一个打开的简单Python脚本-可以说-stackoverflow.com.
Now I would like to build a simple Python script which opens - let say - stackoverflow.com.
在装有google的计算机上,这不是
On a computer, where google is installed it isn't a problem like
from selenium import webdriver
driver = webdriver.Chrome("c:\myproject\driver\chromedriver.exe")
driver.get("https://stackoverflow.com")
但是,如果未安装google chrome且应使用google chrome Portable,如何更改脚本?
However, how to change the script if no google chrome is installed and google chrome portable should be used?
有什么主意吗? 提前非常感谢您,祝您有愉快的一天 安德烈亚斯
Any idea? Thank you very much in advance and have a nice day Andreas
推荐答案
使用选项类:
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "c:\myproject\chromeportable\chrome.exe"
# you may need some other options
#options.add_argument('--no-sandbox')
#options.add_argument('--no-default-browser-check')
#options.add_argument('--no-first-run')
#options.add_argument('--disable-gpu')
#options.add_argument('--disable-extensions')
#options.add_argument('--disable-default-apps')
driver = webdriver.Chrome("c:\myproject\driver\chromedriver.exe",
options=options)
这篇关于Python3,Selenium和Chrome便携式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!