Second question of the day.
This is the code I have written until now.
I am trying to extract the column of Settl.Prices and Vol.Exchange from this table: https://www.eex.com/en/market-data/power/futures/phelix-at-futures#!/2018/7/3
The results in the row is a mess, and I have tried to make it better with re.sub
but I wasn't able to keep numbers, commas, and dots, not to lose position and number decimal separator. Any idea on how to have the two columns stored in two lists?
from bs4 import BeautifulSoup as soup
from selenium import webdriver
from selenium.webdriver.common.by import By
import datetime
import time
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
today=datetime.date.today()
browser = webdriver.Chrome(executable_path=r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe")
my_url = 'https://www.eex.com/en/market-data/power/futures/phelix-at-futures#!/'+str(today.year)+'/'+str(today.month)+'/'+str(today.day-1)
browser.get(my_url)
button = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "ul.tabs.filter_wrap.clearfix li.ng-scope:nth-child(3)>a"))).click()
page_html = browser.page_source
page_soup = soup(page_html, "html.parser")
browser.close()
time.sleep(5)
table = page_soup.find('table')
table_rows = table.findAll('tr')
for tr in table_rows:
list = ""
td = tr.find_all('td')
row = [i.text for i in td]
print(row)
actual output
['\n Cal-19\n ', '\n -\n ', '\n -\n ', '\n -\n ', '\n -\n ', '\n 0.51\n ', '\n -\n ', '\n -\n ', '\n 46.15\n ', '\n -\n ', '\n -\n ', '\n 12\n ', '', '\n\n']
['\n\nloading...\n\nan error occurred while loading the chart...\nPlease reload the chart.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nInvalid Date Format: Please use the format YYYY-MM-DD.\n\n\n\n\nx\n\n\n\n\nIntraday Prices\nSettlement Prices\n\n\n\n\n\n\nall series\n\n\n\n\n\n\n\n\n\n\n\n\n\n']
['\n Cal-20\n ', '\n -\n ', '\n -\n ', '\n -\n ', '\n -\n ', '\n 0.54\n ', '\n -\n ', '\n -\n ', '\n 44.62\n ', '\n -\n ', '\n -\n ', '\n 1\n ', '', '\n\n']
['\n\nloading...\n\nan error occurred while loading the chart...\nPlease reload the chart.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nInvalid Date Format: Please use the format YYYY-MM-DD.\n\n\n\n\nx\n\n\n\n\nIntraday Prices\nSettlement Prices\n\n\n\n\n\n\nall series\n\n\n\n\n\n\n\n\n\n\n\n\n\n']
['\n Cal-21\n ', '\n -\n ', '\n -\n ', '\n -\n ', '\n -\n ', '\n 0.65\n ', '\n -\n ', '\n -\n ', '\n 43.70\n ', '\n -\n ', '\n -\n ', '\n -\n ', '', '\n\n']
['\n\nloading...\n\nan error occurred while loading the chart...\nPlease reload the chart.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nInvalid Date Format: Please use the format YYYY-MM-DD.\n\n\n\n\nx\n\n\n\n\nIntraday Prices\nSettlement Prices\n\n\n\n\n\n\nall series\n\n\n\n\n\n\n\n\n\n\n\n\n\n']
['\n Cal-22\n ', '\n -\n ', '\n -\n ', '\n -\n ', '\n -\n ', '\n 0.55\n ', '\n -\n ', '\n -\n ', '\n 45.08\n ', '\n -\n ', '\n -\n ', '\n -\n ', '', '\n\n']
['\n\nloading...\n\nan error occurred while loading the chart...\nPlease reload the chart.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nInvalid Date Format: Please use the format YYYY-MM-DD.\n\n\n\n\nx\n\n\n\n\nIntraday Prices\nSettlement Prices\n\n\n\n\n\n\nall series\n\n\n\n\n\n\n\n\n\n\n\n\n\n']
['\n Cal-23\n ', '\n -\n ', '\n -\n ', '\n -\n ', '\n -\n ', '\n 0.55\n ', '\n -\n ', '\n -\n ', '\n 45.85\n ', '\n -\n ', '\n -\n ', '\n -\n ', '', '\n\n']
['\n\nloading...\n\nan error occurred while loading the chart...\nPlease reload the chart.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nInvalid Date Format: Please use the format YYYY-MM-DD.\n\n\n\n\nx\n\n\n\n\nIntraday Prices\nSettlement Prices\n\n\n\n\n\n\nall series\n\n\n\n\n\n\n\n\n\n\n\n\n\n']
['\n Cal-24\n ', '\n -\n ', '\n -\n ', '\n -\n ', '\n -\n ', '\n 0.53\n ', '\n -\n ', '\n -\n ', '\n 46.83\n ', '\n -\n ', '\n -\n ', '\n -\n ', '', '\n\n']
['\n\nloading...\n\nan error occurred while loading the chart...\nPlease reload the chart.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nInvalid Date Format: Please use the format YYYY-MM-DD.\n\n\n\n\nx\n\n\n\n\nIntraday Prices\nSettlement Prices\n\n\n\n\n\n\nall series\n\n\n\n\n\n\n\n\n\n\n\n\n\n']
wanted output
46.15,- (the one from the column adjacent)
44.62,-
43.70,-
45.08,-
45.85,-
46.83,-