I'm working on a python script to get some data from a website using selenium Chrome webdriver. Finding the elements needed worked fine for me - until now. Now I'm trying to get an advertisement-ID (value of "data-ad-link".
<div class="header w-brk" style="overflow-wrap: break-word;">
<a href="/iad/immobilien/d/eigentumswohnung/wien/wien-1010-innere-stadt/am-werdertor-etages-de-luxe-344939582/" class="" data-ad-link="344939582">
<span itemprop="name">
AM WERDERTOR - ÉTAGES DE LUXE
</span>
</a>
</div>
From this HTML segment I'd need the value of data-ad-link. I tried solving this problem using
elem = driver.find_elements_by_xpath("//*[@class='']")
for i in range(count):
#uniqueid = elem[i].get_attribute('data-ad-link')
#uniqueid = driver.execute_script('var items = {}; for (index = 0; index < arguments[0].attributes.length; ++index) { items[arguments[0].attributes[index].name] = arguments[0].attributes[index].value }; return items;', elem[i])
print(uniqueid)
In my debugger I'm seeing that creating the list works well - but getting the value doesn't. So I already tried element.get_attribute
which returned None
(also for href!). I tried driver.execute_script
which I found here: Selenium webdriver: How do I find ALL of an element's attributes? which just gives me class, href and rel.
Does anyone know how I could get this value? It would help me so much!
I'm using Selenium (v 3.141.0) on Python