LoginSignup
0
4

More than 5 years have passed since last update.

[備忘録]pythonでbeautiful soupの使い方まとめ

Posted at

pythonでのスクレイピングツールbeautiful soupを使うときの使い方についてまとめました。
スクレイピングって地味によく使うんですよね...

最初のhtml parserの処理

uClient = urllib.request.urlopen(doctor_site)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "html.parser")

タグでの検索(最初に一致したもの)

page_soup.h1

タグでの検索(複数検索)

findAll("h1")

タグ&クラス名での検索(複数検索)

page_soup.findAll("meta",{"name":"description"})

クラスの取得

page_soup.h1.attrs['class']

他に何かあったら適宜追加していきます。
あと、beautiful soupって書き方が色々あったりするから、注意。

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