I'm new to python and was trying to scrape data from a website. So far, i can successfully scrape the data however the output is given in a linear format instead of the table its pulled from. Could someone give me some pointers on how to get the correct output?
import datetime
import pandas as pd
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
chrome_options = Options()
chrome_options.add_experimental_option( "prefs",{'profile.managed_default_content_settings.javascript': 2})
chrome_options.add_argument("-headless")
chrome = webdriver.Chrome('chromedriver', options = chrome_options)
today = datetime.date.today()
first = today.replace(day=1)
lastMonth = first - datetime.timedelta(days=1)
date_range = pd.date_range(start='2019-01-01', end=lastMonth, freq='MS')
date_range.strftime("%B/%Y")
date_list = [i.strftime('%B/%Y') for i in date_range]
base_url = "https://www.horseracing.net/tipsters/sky-sports-racing/alex-hammond/"
length = len(date_list)
i = 41 # set to 41 for testing purposes, I didnt want to loop all the tables until i sorted the output.
while i < length:
page_url = str(base_url)+""+str(date_list[i])
chrome.get(page_url)
EL2 = chrome.find_element(By.CLASS_NAME, 'main-table-container')
print(EL2.text)
i += 1
Current Output
Date
Pos
Tip
Track
Stake
Type
Odds
Result
30th
5th
Clipsham Gold
Yarmouth
1.0 WIN
Nap
9/4
LOST
29th
2nd
Cavendish
Bath
1.0 WIN
Nap
9/4
LOST
28th
2nd
King Of War
Brighton
1.0 WIN
Nap
2/1
LOST
27th
1st
The Vollan
Southwell
1.0 WIN
Nap
11/8
WON
Desired Output (all the sites appended into one dataframe, so I can export to an .xlsx)