I have a table created using 'div' elements, which has dynamic content based on the choice and also the data to be displayed that are generated with javascript. Html structure is like this:
<div class="container-jKD0Exn-">
<div class="shrinkShadowPosition-OFmmj-q_">
<div class="shrinkShadowWrap-OFmmj-q_">
<div class="shrinkShadow-OFmmj-q_">
</div></div></div>
<div class="titleWrap-jKD0Exn-" style="box-shadow:none">
<div class="offsetPadding-jKD0Exn-" style="width:0"></div>
<span class="title-jKD0Exn- apply-overflow-tooltip">Total common shares outstanding</span></div>
<div class="filling-jKD0Exn-"></div>
<div class="values-jKD0Exn- values-ZmRZjHnV">
<div class="value-25PNPwRV">
<div class="wrap-25PNPwRV">
<div>22.32B</div>
</div></div>
<div class="value-25PNPwRV">
<div class="wrap-25PNPwRV">
<div>21.34B</div>
</div></div>
<div class="value-25PNPwRV">
<div class="wrap-25PNPwRV"><div>20.50B</div>
</div></div>
Using below python code, result is like this: Total common shares outstanding22.32B21.34B20.50B19.02B17.77B16.98B16.43B16.33B Instead I would it in a list or in a dtaframe like this:
['Total common shares outstanding',22.32,21.34,20.50B,19.02,17.77,16.98B,16.43,16.33,]
Python code I'm using to scrape data is this one:
from selenium import webdriver
import pandas as pd
import requests, bs4
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
url ='https://www.tradingview.com/symbols/NASDAQ-AAPL/financials-statistics-and-ratios/'
driver = webdriver.Chrome('chromedriver',options=options)
driver.get(url)
html = driver.page_source
#print(html)
soup = bs4.BeautifulSoup(html, 'html.parser')
for title in soup.find_all("div", {"class": "container-jKD0Exn-"}):
print(title.text+'\n')
Is there any way in selenium or beautifulsoap to get a list like that?