Skip to content
Advertisement

Web scraping: help needed last post and find link

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

JavaScript

Thanks for time ans reply!

Advertisement

Answer

First I’d like you to use correct locators, so instead of /html/body/main/div[4]/div[1]/div/div[1]/div[2]/button[2]/span try using this CSS selector .btn--mode-primary.overflow--wrap-on.
In order to get the last comment you can use this XPath: (//div[@class='commentList-item'])[last()] So in order to get the last comment details only your code can be modified to be like this:

JavaScript

UPD
To get the last element on the page, as you described in the comments, you have to change the locator from

JavaScript

to

JavaScript

So that entire code above will be:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement