raj shastri raj shastri - 4 years ago 140
Python Question

Extracting dates from span using Python Selenium

I have this page:

Tripadvisor

For every review published there is a corresponding date in the title attribute,

check this :

<span class="ratingDate relativeDate" title="4 February 2017">Reviewed yesterday </span>


So, for every review published there is a date in the title attribute, my problem is that I am not able to fetch all the dates from the reviews.

I tried with this code:

def Dates():
datediv = driver.find_elements_by_css_selector('div > div.col2of2 > div > div.wrap > div.rating.reviewItemInline > span.ratingDate.relativeDate')
dateatt = datediv.get_Attribute("title")
for date in dateatt:
print(date.text)


But still it does not work and I get the error of

AttributeError: 'list' object has no attribute 'get_Attribute'


Where am I going wrong?

Guy Guy
Answer Source

datediv is list. You need to iterate over it

datediv = driver.find_elements_by_css_selector('div > div.col2of2 > div > div.wrap > div.rating.reviewItemInline > span.ratingDate.relativeDate')
for dateatt in datediv:
    print(dateatt.get_attribute("title"))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download