質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Microsoft Edge

Microsoft Edgeは、マイクロソフト社が開発する新しいWebブラウザです。Windows 10から標準搭載されており、Internet Explorerとは違うレンダリングエンジンが採用されています。

Internet Explorer

Internet Explorer(IE;MSIE)はマイクロソフトが開発したウェブブラウザです。Microsoft Windowsに組み込まれています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

selenium

Selenium(セレニウム)は、ブラウザをプログラムで作動させるフレームワークです。この原理を使うことにより、ブラウザのユーザーテストなどを自動化にすることができます。

Q&A

解決済

2回答

13908閲覧

Python SeleniumでEdgeをIEモードで起動したい

yutchan

総合スコア5

Microsoft Edge

Microsoft Edgeは、マイクロソフト社が開発する新しいWebブラウザです。Windows 10から標準搭載されており、Internet Explorerとは違うレンダリングエンジンが採用されています。

Internet Explorer

Internet Explorer(IE;MSIE)はマイクロソフトが開発したウェブブラウザです。Microsoft Windowsに組み込まれています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

selenium

Selenium(セレニウム)は、ブラウザをプログラムで作動させるフレームワークです。この原理を使うことにより、ブラウザのユーザーテストなどを自動化にすることができます。

0グッド

0クリップ

投稿2021/08/10 02:08

編集2021/08/10 02:27

前提・実現したいこと

Python(3.7)のSeleniumでIEでしか動作しない社内システムのスクレイピングに取り組んでいます。
そこで、msedge.selenium_toolsを利用してEdgeのIEモードを使いたいと考えております。

発生している問題

以下のように記述したのですが、EdgeがChromiumモードで起動します。
EdgeのIEモードで起動させるには、どのように記述すれば良いのでしょうか?
何卒、アドバイスをお願い致します。

試したコード1

python

1from webdriver_manager.microsoft import EdgeChromiumDriverManager 2from msedge.selenium_tools import Edge, EdgeOptions 3from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 4 5dc_ie = DesiredCapabilities.INTERNETEXPLORER.copy() 6dc_ie["ie.edgechromium"] = True 7 8options = EdgeOptions() 9options.use_chromium = True 10 11driver = Edge(executable_path = EdgeChromiumDriverManager(cache_valid_range = 30).install(),options=options,desired_capabilities=dc_ie) 12driver.get('https://google.com') 13

試したコード2

python

1from webdriver_manager.microsoft import EdgeChromiumDriverManager 2from msedge.selenium_tools import Edge, EdgeOptions 3from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 4from selenium import webdriver 5 6dc_ie = DesiredCapabilities.INTERNETEXPLORER.copy() 7dc_ie["ie.edgechromium"] = True 8 9options = webdriver.IeOptions() 10options.use_chromium = True 11 12driver = Edge(executable_path = "IEDriverServer.exe",options=options,desired_capabilities=dc_ie) 13driver.get('https://google.com')

試したこと

c#のサンプルから、capabilityの設定を適切にすればよいのでは?と考え、上記2つのコードを書きました。
リンク1
リンク2

しかし下記Seleniumのドキュメントを見る限り、ie.edgechromiumという設定項目の記述が無く、Pythonでも出来るのか確信も無い状態です。
日本語版リンク
英語版リンク

因みに
コード2でwebdriverを直接指定しているのは、下記現象のためwebdriver_managerがうまく使いこなせなかったからです。
リンク

補足情報(FW/ツールのバージョンなど)

利用環境
OS:windows10

python --version

Python 3.7.3

pip list

Package Version


altgraph 0.17
appdirs 1.4.4
astroid 2.5
beautifulsoup4 4.9.3
certifi 2019.3.9
chardet 3.0.4
colorama 0.4.4
comtypes 1.1.8
configparser 5.0.1
crayons 0.4.0
et-xmlfile 1.0.1
future 0.18.2
gitdb 4.0.5
GitPython 3.1.13
html5lib 1.0.1
idna 2.8
isort 5.7.0
jdcal 1.4
lazy-object-proxy 1.5.2
lint 1.2.1
lxml 4.3.3
mccabe 0.6.1
MouseInfo 0.1.3
msedge-selenium-tools 3.141.3
numpy 1.16.2
opencv-python 4.5.1.48
openpyxl 2.6.2
overlay 1.1.5
pandas 0.24.2
pefile 2019.4.18
Pillow 8.1.1
pings 0.0.1
pip 21.2.3
psutil 5.8.0
PyAutoGUI 0.9.52
PyGetWindow 0.0.9
pyinstaller 4.1
pyinstaller-hooks-contrib 2020.10
pylint 2.7.1
PyMsgBox 1.0.9
pyperclip 1.8.2
PyRect 0.1.4
PyScreeze 0.1.26
python-dateutil 2.8.0
PyTweening 1.0.3
pytz 2019.1
pywin32 300
pywin32-ctypes 0.2.0
requests 2.21.0
selenium 3.141.0
setuptools 40.8.0
six 1.12.0
smmap 3.0.5
soupsieve 2.2
toml 0.10.2
tqdm 4.56.1
typed-ast 1.4.2
urllib3 1.24.1
webdriver-manager 3.2.2
webencodings 0.5.1
wheel 0.35.1
wrapt 1.12.1
xlrd 1.2.0
zenhan 0.5.2

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

下記コードで動作しました。

又、2021/9/1現在最新のドライバーが.3.150.2となっており、3の前に邪魔なピリオドがついているせいで
下記リンク先のようにコードを改造しないとIEDriverManagerでドライバーを持ってこれません。
https://teratail.com/questions/353563?reply=true

python

1from selenium import webdriver 2from webdriver_manager.microsoft import IEDriverManager 3 4ieOptions = webdriver.IeOptions() 5ieOptions.add_additional_option("ie.edgechromium", True) 6ieOptions.add_additional_option("ie.edgepath",'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe') 7driver = webdriver.Ie(executable_path=IEDriverManager().install(), options=ieOptions) 8 9driver.get('https://google.com')

もしくは、下記のように番号が間違っていないバージョン(3.150.1)を指定すれば動作します。

python

1from selenium import webdriver 2from webdriver_manager.microsoft import IEDriverManager 3 4ieOptions = webdriver.IeOptions() 5ieOptions.add_additional_option("ie.edgechromium", True) 6ieOptions.add_additional_option("ie.edgepath",'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe') 7driver = webdriver.Ie(executable_path=IEDriverManager(version='3.150.1'), options=ieOptions) 8 9driver.get('https://google.com')

投稿2021/09/01 06:27

yutchan

総合スコア5

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

ベストアンサー

Optionにset_capabilityというメソッドがあるのですが、これを使っても駄目でしょうか?

python

1from selenium.webdriver.edge.options import Options 2opt = Options() 3opt.set_capability('ie.edgechromium', True)

サンプルを作る暇がないので試してはいないのですが。

投稿2021/08/28 08:30

TANAKAKazuyoshi

総合スコア96

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yutchan

2021/09/01 06:20

教えて頂きありがとうございます。 TANAKA様のコードと少し違うのか実質同じなのか区別がつかないのですが、 いろいろ試した結果、IEモードでの起動に成功出来ました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問