Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Load Website table into Python
petercour
petercour

Posted on

     

Load Website table into Python

On the web you can find countless of tables. Those tables (and any webpage) is defined in HTML. So you need to parse HTML right?

Not exactly, there's a module called Pandas which parses the data for you. That data is then stored in a data structure named data frame.

Say you grab the table fromhttps://www.fdic.gov/bank/individual/failed/banklist.html

#!/usr/bin/python3import pandas as pdimport numpy as npurl ='https://www.fdic.gov/bank/individual/failed/banklist.html'res2=pd.read_html(url)print(res2)print("+"*50)print(res2[0]["Bank Name"])
Enter fullscreen modeExit fullscreen mode

So the line

res2=pd.read_html(url)
Enter fullscreen modeExit fullscreen mode

gets the whole table and puts it in a pandas data frame. That easy!

This line shows the whole table

print(res2)
Enter fullscreen modeExit fullscreen mode

for a specific column

print(res2[0]["Bank Name"])
Enter fullscreen modeExit fullscreen mode

So you can easily grab data from a webpage, without having to parse html language yourself.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

More frompetercour

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp