I am trying to get the date of the tweet using the following code
div_html.parser")
contents = soup.find_all(class_=div_class)
for p in contents:
print(p.time)
but None is printed
the page structure is
CodePudding user response:
Provided that the element is included in your soup
- Classes look high dynamic so better change your selection strategy and use more static id, HTML structure, attriutes.
Following css selector
selects all <time>
that is an directly child of an <a>
:
for t in soup.select('a>time'):
# tag / element
print(t)
# text
print(t.text)
# attribute value
print(t.get('datetime))