0
1

More than 3 years have passed since last update.

僕のBeautifulSoup(Python)

Last updated at Posted at 2019-12-13

自分用のまとめ
随時更新

自分がわかればいいからところどころ用語が間違ってるかも

!見方

#コマンド
    #引数のオプションの説明

BeautifulSoupって何に使うの?

HTMLを解析してスクレイピングやら


モジュール読み込み

import bs4

頻出操作

HTMLインスタンス取得から頻出の解析
#解析用オブジェクト取得
soup = bs4.BeutifulSoup()
    #第一引数にHTMLオブジェクト→webdriver.get_sourceとかで取れるやつ
  #第二引数にHTMLパーサー
      #→代表的なのlxml,html5lib,html.parser

#要素情報で一つ見つける
element = soup.find()
    class= #クラス名
    href= #リンク
  "" #何もつけないとタブ

#要素情報ですべて見つける
element = soup.find_all()
    #引数はfind()と同じ
    #複数ある場合は返り値はリスト

#cssセレクタですべて見つける
element = soup.select()

#見つけた要素のテキスト部分だけにする
element.string
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