I'm using selenium for web scraping. I'm trying to scrape the content of a paragraph within a division of a certain class X. The problem im having is that there are multiple div
with the same class
inside a collapse group, and what i wanna do is take only the first div
of this class
within each collapse group.
so for example when i run this piece of code:
driver.find_elements_by_xpath("//div[@class='X']//p[1])
what happens is that i get all first paragraphs from all divisions containing with the class X
. so im having for each collapse group multiple paragraphs. is there a way i can index the division?
maybe something like:
driver.find_elements_by_xpath("//div[1][@class='X']//p[1])
# or
driver.find_elements_by_xpath("//div[@class='X'][1]//p[1])