webmaster-kazu.com

テクノロジー・データ分析・実践ログ・その他

Webサイトとの対話を自動化するためのライブラリ「MechanicalSoup」のインストール

カテゴリ: Python【初歩から現場実務的なもの】

Webサイトとの対話を自動化するためのライブラリ「MechanicalSoup」のインストールについて解説しています。

「MechanicalSoup」(https://mechanicalsoup.readthedocs.io/en/stable/)は、Cookieを自動的に保存して送信し、リダイレクトを追跡し、リンクを辿りフォームを送信することができます。

■Python

今回のPythonのバージョンは、「3.8.5」を使用しています。(Windows10)(pythonランチャーでの確認)

■MechanicalSoupをインストールする

MechanicalSoupをインストールを行いますが、今回はpipを経由してインストールを行うので、まずWindowsのコマンドプロンプトを起動します。

pip install MechanicalSoup

起動後、上記のコマンドを入力し、Enterキーを押します。

なお、今回は、pythonランチャーを使用しており、Python Version 3.8.5にインストールを行うために、pipを使う場合にはコマンドでの切り替えを行います。

py -3.8 -m pip install MechanicalSoup

切り替えるために、上記のコマンドを入力し、Enterキーを押します。

Defaulting to user installation because normal site-packages is not writeable

Collecting MechanicalSoup

Downloading MechanicalSoup-1.1.0-py3-none-any.whl (19 kB)

Requirement already satisfied: beautifulsoup4>=4.7 in c:\users\user_\appdata\roaming\python\python38\site-packages (from MechanicalSoup) (4.9.3)

Requirement already satisfied: lxml in c:\users\user_\appdata\roaming\python\python38\site-packages (from MechanicalSoup) (4.6.3)

Requirement already satisfied: requests>=2.22.0 in c:\users\user_\appdata\roaming\python\python38\site-packages (from MechanicalSoup) (2.27.1)

Requirement already satisfied: soupsieve>1.2 in c:\users\user_\appdata\roaming\python\python38\site-packages (from beautifulsoup4>=4.7->MechanicalSoup) (2.2.1)

Requirement already satisfied: idna<4,>=2.5 in c:\users\user_\appdata\roaming\python\python38\site-packages (from requests>=2.22.0->MechanicalSoup) (2.10)

Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\user_\appdata\roaming\python\python38\site-packages (from requests>=2.22.0->MechanicalSoup) (1.26.5)

Requirement already satisfied: charset-normalizer~=2.0.0 in c:\users\user_\appdata\roaming\python\python38\site-packages (from requests>=2.22.0->MechanicalSoup) (2.0.12)

Requirement already satisfied: certifi>=2017.4.17 in c:\users\user_\appdata\roaming\python\python38\site-packages (from requests>=2.22.0->MechanicalSoup) (2021.5.30)

Installing collected packages: MechanicalSoup

Successfully installed MechanicalSoup-1.1.0

Enterキーを押すと、インストールが開始され、上記のように「Successfully installed」と表示されます。これが表示されれば、MechanicalSoupが正常にインストールされたことになります。

なお、今回はMechanicalSoupのバージョン1.1.0をインストールしました。