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
Aucun commentaire:
Enregistrer un commentaire