## 前言 本來是想要像按連結的時候一樣開新分頁用selenium,但沒找到方法。 用edge的話,現在找到的辦法都會新建一個新的使用者的瀏覽器設定,但沒辦法弄在原本的使用者設定。 ## 使用 ### 找到 edge 檔案的原路徑 找到Edge檔案存放的位置:  在 terminal 中移動到上面那張圖的「開始位置」: ```shell cd "C:\Program Files (x86)\Microsoft\Edge\Application" ```  ### 打開 edge 在此目錄下輸入: ```shell .\msedge.exe --remote-debugging-port=9222 --user-data-dir="C:\Users\Chunill\Program\python\web_crawler\AutomationProfile" ``` 其中 `--remote-debugging-port=9222` 是接口位置,設什麼都可以,不要撞到就好了。而 `--user-data-dir="C:\Users\Chunill\Program\python\web_crawler\AutomationProfile"` 是瀏覽器使用者設定儲存的位置(新增檔案在你想放置的地方),我是直接放在寫爬蟲專用的資料夾裡。 ### 使用 selenium 來打開瀏覽器 接著可以使用以下的程式碼來開啟瀏覽器: ```python from selenium import webdriver from selenium.webdriver.edge.options import Options def getEdgeBrowser(): edge_options = Options() edge_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222") browser = webdriver.Edge(options=edge_options) return browser ``` 其中, `"127.0.0.1:9222"` 中的9222就是之前設定的接口。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up