#dependencies import requests from bs4 import BeautifulSoup import json url = 'http://api.scraperapi.com?api_key=51e43be283e4db2a5afbxxxxxxxxxxx&url=https://datatables.net/examples/styling/stripe.html' #empty array employee_list = [] #requesting and parsing the HTML file response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') #selecting the table table = soup.find('table', class_ = 'stripe') #storing all rows into one variable for employee_data in table.find_all('tbody'): rows = employee_data.find_all('tr') #looping through the HTML table to scrape the data for row in rows: name = row.find_all('td')[0].text position = row.find_all('td')[1].text office = row.find_all('td')[2].text age = row.find_all('td')[3].text start_date = row.find_all('td')[4].text salary = row.find_all('td')[5].text #sending scraped data to the empty array employee_list.append({ 'Name': name, 'Position': position, 'Office': office, 'Age': age, 'Start date': start_date, 'salary': salary }) #importing the array to a JSON file with open('employee_data', 'w') as json_file: json.dump(employee_list, json_file, indent=2)