I am new to selenium and I want to scrape data from https://www.nasdaq.com/market-activity/stocks/aapl
I am particularly interested in data from Summary Data section.
As an example, I want to scrape the following data:
- Exchange: NASDAQ-GS
- Sector: Technology
- Industry: Computer Manufacturing
Here is the part of HTML code from the table that I want to extract:
<table class="summary-data__table" role="table">
<thead class="visually-hidden" role="rowgroup">
<tr role="row">
<th role="columnheader" scope="col">Label</th>
<th role="columnheader" scope="col">Value</th>
</tr>
</thead>
<tbody class="summary-data__table-body" role="rowgroup"><tr class="summary-data__row" role="row" data-first-five="true" data-first-ten="true">
<td role="cell" class="summary-data__cellheading">Exchange</td><td role="cell" class="summary-data__cell">NASDAQ-GS</td>
</tr><tr class="summary-data__row" role="row" data-first-five="true" data-first-ten="true">
<td role="cell" class="summary-data__cellheading">Sector</td><td role="cell" class="summary-data__cell">Technology</td>
</tr><tr class="summary-data__row" role="row" data-first-five="true" data-first-ten="true">
<td role="cell" class="summary-data__cellheading">Industry</td><td role="cell" class="summary-data__cell">Computer Manufacturing</td>
</tr><tr class="summary-data__row" role="row" data-first-five="true" data-first-ten="true">
<td role="cell" class="summary-data__cellheading">1 Year Target</td><td role="cell" class="summary-data__cell">$275.00</td>
</tr><tr class="summary-data__row" role="row" data-first-five="true" data-first-ten="true">
<td role="cell" class="summary-data__cellheading">Today's High/Low</td><td role="cell" class="summary-data__cell">$271.00/$267.30</td>
</tr><tr class="summary-data__row" role="row" data-first-ten="true">
<td role="cell" class="summary-data__cellheading">Share Volume</td><td role="cell" class="summary-data__cell">26,547,493</td>
</tr></tbody>
</table>
This is the Python code that I have so far:
driver = webdriver.Chrome(executable_path='chromedriver.exe')
driver.get('https://www.nasdaq.com/market-activity/stocks/aapl')
time.sleep(20)
elements = driver.find_element_by_class_name("summary-data__table")
I am stuck as I can't iterate through the table using the code above.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…