I try to scrape the NASDAQ values from the www.n-tv.de website. I'm crawling with SELENIUM through the Sites. The Stock Values are on the Site in Tables.
The Source COde of Table for Example is like:
<div class="tableholder">
<table class="cnttable zebra to le">
<thead>
<tr>
<th>Name</th><th class="ri">Kurs</th><th class="ri">%</th><th class="ri">Absolut</th><th class="ri hidden-xs-down">Relation</th><th class="ri hidden-xs-down">Zeit</th><th class="ri hidden-xs-down hidden-sm-down">Handelsvolumen</th><th class="hidden-xs-down hidden-sm-down">ISIN</th>
</tr>
</thead>
<tbody>
<tr class="linked" onclick="document.location='https://www.n-tv.de/boersenkurse/aktien/activision-blizzard-295693';">
<td>Activision Blizzard</td>
<td class="ri"><span class="icon_neg">66,53$</span></td>
<td class="ri"><span class="neg">-1,42%</span></td>
<td class="ri"><span class="neg">-0,96</span></td>
<td class="relation hidden-xs-down"><span class="neg"> <span><span></span></span><span style="border-width: 24px;"></span></span></td>
<td class="ri hidden-xs-down">31.12.</td>
<td class="ri hidden-xs-down hidden-sm-down">8 Tsd.</td>
<td class="hidden-xs-down hidden-sm-down">US00507V1098</td>
</tr>
...
</tbody>
</table>
</div>
SO I do not understand the following Problem:
Seachrching the Web Elements of NASDAQ table i will do per Xpath :
nasdaq = driver.find_element_by_xpath('//table[@class="cnttable zebra to le"]')
rows_nasdaq = nasdaq.find_elements_by_class_name('linked')
I have made another solution, that works correctly by searching the tableholder elements (3 on this site) and after listing them then taking only the third object, but i really want to understand, why that xpath selctor above is not working to this the element , although i have the class name unique on this site as an attribute of the table tag element.
I do not use css or something, has someone an idea, why in this case the xpath is not matching ??
Assumed yo like to scrape this url https://www.n-tv.de/boersenkurse/suche/?suchbegriff=to%20le.
You have to wait for element you try to find is present in the DOM and can use
selenium waits
for this:Need to be imported
Example:
Output
EDIT
Based on your comment I got the "link" - Issue, there was no table under url https://www.n-tv.de/ but the nasdaq is linked by https://www.n-tv.de/boersenkurse/indizes/nasdaq-849974 and there I found your table.
So it is not necessary to wait, but it can't hurt either. I have imported the table directly with
pandas
into a dataframe:Output
Note: Relation column is empty, cause there is no text stored in it and you can simply drop it, if you like