Search code examples
htmlpython-3.xseleniummeta-tagsmicrodata

How to retrieve content value from Microdata meta tag inside a class


I am trying to retrive all the values of the dateCreated.

I am using Selenium webdriver with Python.

<div class="bv-content-datetime" role="presentation">
    <meta itemprop="dateCreated" content="2018-08-28"> -- this one
    <meta itemprop="datePublished" content="2018-08-28"> 
<span class="bv-content-datetime-dot" aria-hidden="true">·</span> 
<span class="bv-content-datetime-stamp">vor 11 Monaten &nbsp;</span> </div>

I have been trying to retrieve "2018-08-28".


Solution

  • Use get_attribute('content')

    driver.find_element_by_css_selector('[itemprop="dateCreated"]').get_attribute('content')
    

    EDIT:

    use for loop for n number of elements.

    for item in driver.find_elements_by_css_selector('[itemprop="dateCreated"]'):
      print(item.get_attribute('content'))