samedi 1 mai 2021

How can I get the tooltip text on reddit?

I am trying to build some kind selenium scrapper for reddit. However, I do find myself having some trouble to get the timestamp shown in the pic.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.wait import WebDriverWait
from time import sleep # this should go at the top of the file
from bs4 import BeautifulSoup as bs

sleep(5)
driver = webdriver.Chrome(ChromeDriverManager().install())

driver.get('https://www.reddit.com/r/StockMarket/')

title = driver.find_element_by_css_selector('h3._eYtD2XCVieq6emjKBH3m').text
timestamp = driver.find_element_by_css_selector('a._3jOxDPIQ0KaOWpzvSQo-1s').text
print(title)
print(timestamp)

[Output]: We’ve been doing it all wrong
          5 hours ago

Desired result




Aucun commentaire:

Enregistrer un commentaire