Skip to content

Instantly share code, notes, and snippets.

@kipronokoech
Created July 25, 2020 21:54
Show Gist options
  • Save kipronokoech/6bad3a8f7210904091235453b8764086 to your computer and use it in GitHub Desktop.
Save kipronokoech/6bad3a8f7210904091235453b8764086 to your computer and use it in GitHub Desktop.
# Lets go ahead and scrape first table with HTML code gdp[0]
table1 = gdp[0]
# the head will form our column names
body = table1.find_all("tr")
# Head values (Column names) are the first items of the body list
head = body[0] # 0th item is the header row
body_rows = body[1:] # All other items becomes the rest of the rows
# Lets now iterate through the head HTML code and make list of clean headings
# Declare empty list to keep Columns names
headings = []
for item in head.find_all("th"): # loop through all th elements
# convert the th elements to text and strip "\n"
item = (item.text).rstrip("\n")
# append the clean column name to headings
headings.append(item)
print(headings)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment