adrian
adrian

Reputation: 148

How can I extract the full datetime from a Beautifulsoup ResultSet?

I'm trying to extract the date and time of an Instagram post using selenium and beautifulsoup. I'm not sure how to extract the datetime element.

from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://www.instagram.com/p/B5LeHK2h4p0/')

html = driver.page_source
soup = BeautifulSoup(html)

dateTime= soup.select('time._1o9PC.Nzb55')

If I print dateTime this is what I get:

[<time class="_1o9PC Nzb55" datetime="2019-11-22T19:20:29.000Z" title="Nov 22, 2019">November 22, 2019</time>]

also, type(dateTime) yields:

<class 'bs4.element.ResultSet'>

How can I extract 2019-11-22T19:20:29.000Z ?

Upvotes: 0

Views: 951

Answers (1)

MendelG
MendelG

Reputation: 20038

dateTime = soup.select('time._1o9PC.Nzb55' )[0]['datetime']

[0] To extract it from the list, and than access the datetime tag.

Upvotes: 1

Related Questions