LoginSignup
1
0

More than 1 year has passed since last update.

【2021年度版】Selenium BasicインストールからPythonによるWebスクレイピング実行まで Windows10(64bit)編

Last updated at Posted at 2020-12-24

はじめに

Selenium Basicをインストールする機会が多いのでマニュアル化しました。
本記事はPythonでWebスクレイピングをしたいWindows10(64bit)ユーザー向けの記事です。

Pythonインストール方法は以下記事を参考にしてください。
https://qiita.com/ssbb/items/b55ca899e0d5ce6ce963

Webブラウザ要件

今回はGoogle ChromeでWebスクレイピングをするため、あらかじめGoogle Cromeをインストールしてください。

Selenium Basicとは

Selenium Basic 公式サイト(https://florentbr.github.io/SeleniumBasic/) には以下のように説明されています。要するに、Webスクレイピングをするに必要なファイルと思っておけば大丈夫です。

Description
It makes it possible to automate web browsing using Excel and VBA code or using a simple VBS file executed by double-clicking on it. User's actions can be recorded using the Firefox plugin named "Selenium IDE" and translated to VBA or VBS with the provided formatters.

Selenium Basic インストール

Selenium Basic 公式サイト(https://florentbr.github.io/SeleniumBasic/) にアクセスしてページ中段にある[Release page]をクリックします。
1.png

exeファイルをクリックしてダウンロードします。
2.png

ダウンロードが完了したらexeファイルを起動します。[Welcome to the Selenium Basic Setup Wizard]とセットアップウィザードが表示されたら[Next]をクリックします。
3.png

ライセンス同意を求められるので[I accept the agreement]にチェックを入れて[Next]をクリックします。
4.png

インストールするコンポーネントはデフォルトのまま変更せず[Next]をクリックします。
5.png

インストール内容に問題がなければ[Install]をクリックします。
6.png

[Completing the Selenium Basic Setup Wizard]と表示されればインストールが成功しましたので[Finish]をクリックして閉じます。
7.png

ChromeDriver インストール

SelenumBasicに同梱されているGoogle Chrome用のWebドライバは最新版のGoogle Chromeに対応していません。そのため、以下のページからお使いのGoogle Chromeとバージョンが同じChromeDriverをダウンロードします。

ChromeDriver - WebDriver for Chrome
https://sites.google.com/chromium.org/driver/

私が使っているGoogle Chromeのバージョンは「87.0.4280.88」のため「ChromeDriver 87.0.4280.88」をクリックします。
8.png

Windows版のChromeDriverが必要なので「chromedriver_win32.zip」をクリックします。
9.png

ダウンロードが完了しましたらzipファイルを解凍して「chromedriver.exe」を任意のディレクトリに配置します。

(例)Cドライブ直下に「ChromeDriver」というフォルダを作成し「chromedriver.exe」を配置
10.png

Python用 Seleniumライブラリ インストール

コマンドプロンプトを起動して、以下コマンドを実行します。

pip install selenium

[Successfully installed selenium]と表示されればインストール成功です。
11.png

動作確認

コマンドプロンプトを起動して、以下コマンドを実行します。
[executable_path]はChromeDriverを配置したディレクトリパスにします。

python
from selenium import webdriver
webdriver.Chrome(executable_path=r'C:\ChromeDriver\chromedriver.exe')

12.png

[DevTools listening on ws・・・(省略)]と出力後、暫くしてブラウザが起動されれば成功です。
13.png

最後に

実際のWebスクレイピングで使用するメソッドは以下でまとめていますので参考になれば幸いです。

【2021年度版】Python + Selenium よく使う操作メソッドまとめ
https://qiita.com/ssbb/items/306ec9a1dbecd77d001b

最後まで読んでいただきありがとうございます!

1
0
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
1
0