November 2017
Intermediate to advanced
226 pages
5h 59m
English
We can extract the data from HTML to .csv or Excel documents as following:
import urllib.request import pandas as pd from bs4 import BeautifulSoup url = "https://www.w3schools.com/html/html_tables.asp" try: page = urllib.request.urlopen(url) except Exception as e: print(e) pass soup = BeautifulSoup(page, "html.parser") table = soup.find_all('table')[0] new_table = pd.DataFrame(columns=['Company', 'Contact', 'Country'], index=range(0, 7)) row_number = 0 for row in table.find_all('tr'): column_number = 0 columns = row.find_all('td') for column in columns: new_table.iat[row_number, column_number] = column.get_text() ...Read now
Unlock full access