DEV Community

Cover image for Load Website table into Python
petercour
petercour

Posted on

2

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 from https://www.fdic.gov/bank/individual/failed/banklist.html

#!/usr/bin/python3
import pandas as pd
import numpy as np

url ='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 mode Exit fullscreen mode

So the line

res2=pd.read_html(url)
Enter fullscreen mode Exit 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 mode Exit fullscreen mode

for a specific column

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

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

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay