First, sorry for my poor English.
Actually, I have a script which scrapes a website to find comments in webpage, in python.
Its for scrape all messages in page, but I will want scrape just last post.
How to do this please?
Too, I will want to find web links probably posted in last message, but a full link.
Its possible?
Here is the webpage link and script:
https://www.dealabs.com/discussions/suivi-erreurs-de-prix-1063390?page=9999
#!/usr/bin/env python3
# https://www.jeuxvideo.com/forums/42-47-66784467-1-0-1-0-aide-scraping-python-forum-dealabs.htm
# scraping_dealabs.py
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
url = "https://www.dealabs.com/discussions/suivi-erreurs-de-prix-1063390?page=9999"
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get(url)
# Accepter les cookies
button = WebDriverWait(driver, 2).until(
EC.element_to_be_clickable((By.XPATH, "/html/body/main/div[4]/div[1]/div/div[1]/div[2]/button[2]/span"))
)
button.click()
# On recherche les commentaires et on affiche le texte
comments = driver.find_elements_by_class_name("commentList-item")
for comment in comments:
_id = comment.get_attribute("id")
author = comment.find_element_by_class_name('userInfo-username').text
content = comment.find_element_by_class_name('userHtml-content').text
timestamp = comment.find_element_by_class_name('text--color-greyShade').text
comment_url = f"{url}#{_id}"
print("Posté par", author)
print(content)
print("Publication:", timestamp)
print("Lien du commentaire:")
print(comment_url)
print('-' * 30)
driver.close()
Thanks for time ans reply!