'How to exclude last line from scraped content in python selenium

content = driver.find_elements(By.XPATH,'//div[@id="content"]/p')

Now there is a list of paragraphs that were scraped, like- content[0],content[1].....content[9] The number of paragraph is not fixed everytime, I want to delete the last paragraph from the content.



Solution 1:[1]

You could use list slicing to keep everything except the last item:

content = driver.find_elements(By.XPATH,'//div[@id="content"]/p')[:-1]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HedgeHog