LoginSignup
0
0

More than 3 years have passed since last update.

Beautifulsoupでtableをjsonで取得するもっともシンプルな方法

Posted at

環境

beautifulsoup4==4.9.1

やり方

output_json = {}
table = soup.find("table", class_="table_class foo bar")
rows = table.findAll("tr")

for row in rows:
    json[row.find("td").text.strip()] = row.find("th").text.strip()

print(output_json)

これだけ😄

みなさんがやる時はtableのclass_に取得したいテーブルのクラスを書くだけ

参考

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