如何在普通浏览器中使用 selenium [英] how can I use selenium with my normal browser
问题描述
是否可以将 selenium 连接到我通常使用的浏览器而不是驱动程序?对于正常浏览,我使用带有多个插件的 chrome - 添加 block plus、flashblock 等等.我想尝试使用此特定配置加载站点.我该怎么做?
Is it possible to connect selenium to the browser I use normally instead a driver? For normal browsing I am using chrome with several plugins - add block plus, flashblock and several more. I want to try to load a site using this specific configuration. How can I do that?
p.s - 我不想像这个问题一样只连接到打开的浏览器:
p.s - I dont want to connect only to an open browser like in this question :
我不在乎是否使用驱动程序生成进程.我只想要完整的浏览器配置 - cookie、插件、字体等.
I dont care if I spawn the process using a driver. I just want the full browser configuration - cookies,plugins,fonts etc.
谢谢
推荐答案
首先,您需要下载ChromeDriver
,然后将可执行文件的路径放到 PATH
环境变量中,或者在 executable_path
中传递路径> 论点:
First, you need to download the ChromeDriver
, then either put the path to the executeable to the PATH
environment variable, or pass the path in the executable_path
argument:
from selenium import webdriver
driver = webdriver.Chrome(executable_path='/path/to/executeable/chrome/driver')
为了加载扩展程序,您需要设置 ChromeOptions
:
In order to load extensions, you would need to set ChromeOptions
:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_extension('Adblock-Plus_v1.4.1.crx')
driver = webdriver.Chrome(chrome_options=options)
您还可以保存您拥有的 chrome 用户配置文件并将其加载到 ChromeDriver
:
You can also save the chrome user profile you have and load it to the ChromeDriver
:
options = webdriver.ChromeOptions()
options.add_argument('--user-data-dir=/path/to/my/profile')
driver = webdriver.Chrome(chrome_options=options)
另见:
这篇关于如何在普通浏览器中使用 selenium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!