2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Windows 10 + Python3 + selenium + msedgedriver で headless edge(Chromium) を試してみる

Last updated at Posted at 2020-06-09

目的

Windows 10 + Python3 + selenium + msedgedriver で headless edge(Chromium) を試してみる
Windows10 + Python3 + Selenium4でChromeとEdgeをheadlessで起動してみる はこちら

WebDriverのインストール

ヘルプとフィードバック -> Microsoft Edge よりEdgeのバージョンをチェックする
今日時点では バージョン 83.0.478.45 (公式ビルド) (64 ビット)
WebDriverよりバージョンに合わせて edgedriver_win64.zip をダウンロード後
適当なフォルダに解凍する -> C:\Dev\Tools\edgedriver_win64
上記のフォルダを環境変数に登録後動作を確認する


\> msedgedriver
Starting MSEdgeDriver 83.0.478.45 (fa71536bbfc4d8c41db9e9b61b8b5f71c6c64f0c) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping MSEdgeDriver safe.
MSEdgeDriver was started successfully.

python用のパッケージをインストールする

※seleniumのバージョン指定は必要ないようだ(現在==3.141.0がインストールされている)


\> pip3 install msedge-selenium-tools selenium
\> pip3 list | grep selenium
selenium            3.141.0

サンプルコード

import time
from msedge.selenium_tools import Edge, EdgeOptions

# Launch Microsoft Edge (Chromium)
options = EdgeOptions()
options.use_chromium = True
options.binary_location = r"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"
options.add_argument("headless")        #Chrome と合わせて欲しいぞ・・・
options.add_argument("disable-gpu")
driver = Edge(options = options)

driver.get('https://www.google.co.jp/')

html = driver.page_source
print(html)

# time.sleep(5)
print('done')
driver.quit()

参考にしたサイトはこちら

テストオートメーションに WebDriver (Chromium) を使用する
microsoft/edge-selenium-tools
WebDriver
GNU utilities for Win32
Selenium Python(ABC順)

2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?