簡體   English   中英

如何將您從測試瀏覽器所做的更改保存到實際瀏覽器? (硒)

[英]How to save changes you made from test browser to actual browser? (selenium)

在我開始弄亂 selenium 之前,我應該問這個問題,但我最初是啟動它,所以我會讓它配置我的瀏覽器設置。 在我的代碼中取得了巨大的成功和時間之后,我能夠獲得代碼來執行我想要使用 chrome 進行的配置。 我每次啟動代碼時都會彈出一個測試瀏覽器並且沒有想到它,因為我確實需要在弄亂我的實際瀏覽器之前測試我的代碼。

但是現在我完成了我的代碼並運行它,我看到了正在制作的配置,然后我意識到了。 沒有對我的實際瀏覽器進行配置。 無論如何讓我的代碼運行到我的實際瀏覽器並進行更改?

您需要擁有 ChromeDriver,然后將可執行文件的路徑放到 PATH 環境變量中,或者在 executable_path 參數中傳遞路徑:

from selenium import webdriver
driver = webdriver.Chrome(executable_path='/path/to/executeable/chrome/driver')

為了加載擴展,您需要設置 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:

options = webdriver.ChromeOptions()
options.add_argument('--user-data-dir=/path/to/my/profile')
driver = webdriver.Chrome(chrome_options=options)

也可以看看:

使用帶有擴展名的 Python 運行 Selenium WebDriver(.crx 文件)

ChromeDriver 功能/選項

在 Python 中使用帶有 Selenium 的默認 Chrome 配置文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM