LoginSignup
0
1

More than 1 year has passed since last update.

BeautifulSoupによるHTML解析でのエラー

Posted at

HTMLからデータをスクレイピングする際に、BeautifulSoupを使用する。

Python上でBeautifulSoupを使用する際に以下のようなコードを記述した。

import requests
from bs4 import BeautifulSoup

url = "https://www.python.org/"
r = requests.get(url)
soup = BeautifulSoup(r.content,"lxml")
print(soup)

これを実行しようとしたところ以下のエラーが出た。

error
Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

解決策

BeautifulSoupのインストール関係に問題があった。
標準のimportでは"lxml"はインストールされていない。
よってこれをインストールする必要がある。

解決策
pip install lxml

これをすることにより、正常に動かすことができた。

長いためここには記載しないが、実際に動かしてみて確認してみてください。

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