Windowsのバッチファイルを使うことで、Google ChromeやInternet ExplorerなどのWebブラウザを指定して、特定のURLのサイトを開くことができます。本記事では、その方法を紹介します。
既定のブラウザで所定のURLを開く方法
まず最初は、自らのPCに設定されている既定のブラウザで、特定のURLを開く方法を紹介します。その場合は、バッチファイルを以下のように記述することで所定のURLを開くことができます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start "" http://tecsingularity.com/
「http://tecsingularity.com/」の部分を、開きたいWebサイトのURLに変更してください。
指定したブラウザで所定のURLを開く方法
次に、ブラウザを指定して所定のURLを開く方法を紹介します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start "" "C:\Program Files\Google\Chrome\Application\chrome.exe" http://tecsingularity.com/
start "" "C:\Program Files (x86)\Internet Explorer\iexplore.exe" http://tecsingularity.com/
2行目がGoogle chrome、3行目がInternet Explorerで所定のURLを開く場合のバッチファイルとなります。
「”C:\Program Files\Google\Chrome\Application\chrome.exe”」あるいは「”C:\Program Files (x86)\Internet Explorer\iexplore.exe”」の部分が、使用したいWebブラウザの実行ファイルの位置となります。
そのため、Google chromeやInternet Explorerに限らず、開くのに使いたいWebブラウザの実行ファイルの位置のパスを入れることで、指定のWebブラウザでサイトを開くことができるようになります。
まとめ
今回はWindowsのバッチファイルでWebブラウザを自動で開く方法を確認しました。
PythonとSelenium等を使うことによって、より高度なWebブラウザの制御ができるようになりますが、バッチファイルには環境構築が不要で、テキストファイル一つで簡単に実行できるというメリットがあります。そのため、用途に応じて使い分けると良いでしょう。
Seleniumを使って、より高度なWebブラウザの自動制御を行う場合には、以下の記事を参考にしてみてください。