This is my code to extract data from the DOL website for a project I'm doing for my portfolio. The code does extract all of the data that I need, however it runs really slowly. I think it took like 15 minutes for it to finish extracting everything. I would really appreciate if someone could just point me in the right direction.
import pandas as pd
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
url = 'https://oui.doleta.gov/unemploy/claims.asp'
driver = webdriver.Chrome(executable_path=r"C:\Program Files (x86)\chromedriver.exe")
driver.implicitly_wait(10)
driver.get(url)
driver.find_element_by_css_selector('input[name="level"][value="state"]').click()
Select(driver.find_element_by_name('strtdate')).select_by_value('2020')
Select(driver.find_element_by_name('enddate')).select_by_value('2021')
driver.find_element_by_css_selector('input[name="filetype"][value="html"]').click()
select = Select(driver.find_element_by_id('states'))
for opt in select.options:
opt.click()
input('Press ENTER to submit the form')
driver.find_element_by_css_selector('input[name="submit"][value="Submit"]').click()
rows = driver.find_elements_by_xpath('//*[@id="content"]/table/tbody')
unemployment = []
# Iterate over the rows
# Loop through tables from url with help of BeautifulSoup
for table in rows:
headers = []
for head in table.find_elements_by_xpath('//*[@id="content"]/table/tbody/tr[2]/th'):
headers.append(head.text)
values = []
for row in table.find_elements_by_xpath('//*[@id="content"]/table/tbody/tr')[2:]:
values = []
for col in row.find_elements_by_xpath("./*[name()='th' or name()='td']"):
values.append(col.text)
if values:
unemp_dict = {headers[i]: values[i] for i in
range(len(headers))}
unemployment.append(unemp_dict)
input('Press ENTER to close the automated browser')
driver.quit()
```