webmaster-kazu.com

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

【Python】Webサイトからコンテンツを取得する「Lassie」のインストール

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

Webサイトからコンテンツを取得する「Lassie」のインストールについて解説しています。

「Lassie(https://lassie.readthedocs.org/,https://github.com/michaelhelmick/lassie/)」は、Webサイトから基本的なコンテンツを取得することができるPythonライブラリです。

■Python

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

■Lassieをインストールする

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

pip install lassie

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

なお、今回は、pythonランチャーを使用しており、Python Version 3.8.5にインストールを行うために、バージョンの切り替えを行います。

py -3.8 -m pip install lassie

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

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

Collecting lassie

Downloading lassie-0.11.11.tar.gz (12 kB)

Installing build dependencies ... done

Getting requirements to build wheel ... done

Preparing metadata (pyproject.toml) ... done

Collecting beautifulsoup4<4.10.0,>=4.9.0

Using cached beautifulsoup4-4.9.3-py3-none-any.whl (115 kB)

Collecting python-oembed

Downloading python-oembed-0.2.4.tar.gz (8.0 kB)

Preparing metadata (setup.py) ... done

Requirement already satisfied: requests<3.0.0,>=2.18.4 in c:\users\user_\appdata\roaming\python\python38\site-packages (from lassie) (2.27.1)

Collecting html5lib==1.0b10

Downloading html5lib-1.0b10-py2.py3-none-any.whl (112 kB)

---------------------------------------- 112.6/112.6 kB 819.0 kB/s eta 0:00:00

Requirement already satisfied: setuptools>=18.5 in c:\users\user_\appdata\roaming\python\python38\site-packages (from html5lib==1.0b10->lassie) (62.3.1)

Requirement already satisfied: six in c:\users\user_\appdata\roaming\python\python38\site-packages (from html5lib==1.0b10->lassie) (1.16.0)

Requirement already satisfied: webencodings in c:\users\user_\appdata\roaming\python\python38\site-packages (from html5lib==1.0b10->lassie) (0.5.1)

Requirement already satisfied: soupsieve>1.2 in c:\users\user_\appdata\roaming\python\python38\site-packages (from beautifulsoup4<4.10.0,>=4.9.0->lassie) (2.3.2.post1)

Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\user_\appdata\roaming\python\python38\site-packages (from requests<3.0.0,>=2.18.4->lassie) (1.26.9)

Requirement already satisfied: charset-normalizer~=2.0.0 in c:\users\user_\appdata\roaming\python\python38\site-packages (from requests<3.0.0,>=2.18.4->lassie) (2.0.12)

Requirement already satisfied: idna<4,>=2.5 in c:\users\user_\appdata\roaming\python\python38\site-packages (from requests<3.0.0,>=2.18.4->lassie) (3.3)

Requirement already satisfied: certifi>=2017.4.17 in c:\users\user_\appdata\roaming\python\python38\site-packages (from requests<3.0.0,>=2.18.4->lassie) (2021.10.8)

Building wheels for collected packages: lassie, python-oembed

Building wheel for lassie (pyproject.toml) ... done

Created wheel for lassie: filename=lassie-0.11.11-py3-none-any.whl size=13660 sha256=19f6ba9849ea4c6cf239c11d4c674c65b1a244857258405c1fc760964362140e

Stored in directory: c:\users\user_\appdata\local\pip\cache\wheels\85\ad\97\12406a52559d2c61a38fb36ec68df014d1c2dc98d07dc6afcd

Building wheel for python-oembed (setup.py) ... done

Created wheel for python-oembed: filename=python_oembed-0.2.4-py3-none-any.whl size=8350 sha256=baa4ae923b65479c2cee2e730823fe050663708e44105a8f3a462668e46ed77c

Stored in directory: c:\users\user_\appdata\local\pip\cache\wheels\4a\b0\91\9f5670b0c18a61de9e9f678ca63ddb3b1105efe1c0c35abfd7

Successfully built lassie python-oembed

Installing collected packages: python-oembed, html5lib, beautifulsoup4, lassie

Attempting uninstall: html5lib

Found existing installation: html5lib 1.1

Uninstalling html5lib-1.1:

Successfully uninstalled html5lib-1.1

Attempting uninstall: beautifulsoup4

Found existing installation: beautifulsoup4 4.11.1

Uninstalling beautifulsoup4-4.11.1:

Successfully uninstalled beautifulsoup4-4.11.1

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.

xhtml2pdf 0.2.5 requires html5lib>=1.0, but you have html5lib 1.0b10 which is incompatible.

weasyprint 54.2 requires html5lib>=1.1, but you have html5lib 1.0b10 which is incompatible.

wagtail 2.14.1 requires Pillow<9.0.0,>=4.0.0, but you have pillow 9.1.1 which is incompatible.

seleniumbase 3.1.0 requires beautifulsoup4==4.11.1; python_version >= "3.6", but you have beautifulsoup4 4.9.3 which is incompatible.

pygooglenews 0.1.2 requires dateparser<0.8.0,>=0.7.6, but you have dateparser 1.1.1 which is incompatible.

Successfully installed beautifulsoup4-4.9.3 html5lib-1.0b10 lassie-0.11.11 python-oembed-0.2.4

WARNING: There was an error checking the latest version of pip.

Enterキーを押すと、インストールが開始され、上記のように「Successfully installed」と表示されます。これが表示されれば、lassieが正常にインストールされたことになりますが、今回は「ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.(ERROR: pip の依存性解決は現在インストールされているすべてのパッケージを考慮に入れていません。この挙動は以下のような依存関係の衝突の原因となっています。)」というエラーが出力してしまいました。このため、インストールする際は、こちらとしては仮想環境の構築を行い、インストールすることを推奨します。

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