In: Computer Science
Using HTML/Javascript (if needed) I want to create a table for a website that pulls data from another website where the data is being updated on. Example: https://investors.coca-colacompany.com/stock-information/historical-data
I cannot just put in the numbers to a table as they will be getting updated daily. So it needs to link the the website elements.
DATE | OPEN | HIGH | LOW | CLOSE | VWAP | VOLUME | % CHG | CHANGE | TRADE VAL | TOTAL TRADES |
---|---|---|---|---|---|---|---|---|---|---|
2020-10-13 | -- | -- | -- | 51.09 | -- | -- | 0.00% | -- | -- | -- |
2020-10-12 | 50.84 | 51.525 | 50.83 | 51.09 | 51.155 | 11.39m | 0.55% | 0.28 | 582,437,982.00 | 70,341 |
2020-10-09 | 50.67 | 51.23 | 50.60 | 50.81 | 50.874 | 11.41m | 0.69% | 0.35 | 580,070,644.00 | 80,826 |
Table from:
https://investors.coca-colacompany.com/stock-information/historical-data
from urllib.request import urlopen
from bs4 import BeautifulSoup
import pandas as pd
def scrap():
html = urlopen("https://investors.coca-colacompany.com/stock-information/historical-data").read()
soup = BeautifulSoup(html, 'lxml')
table = soup.find('table',{"class":"qmod-table qmod-table-hover qmod-pricehistory-table nowrap dataTable no-footer dtr-column collapsed"})
price = []
rows = table.find_all('tr')
for row in range(len(rows)):
price_row = []
columns = rows[row].findAll('td')
for column in columns:
price_row.append(column.getText())
price.append(team_row)
return price
if __name__ == "__main__":
price_matrix = scrap()
## Use the price matrix according to your suitability
Please find the above code for the approach, if found any issues please comment, it will be resolved as soon as possible.