How to collect multiple images before and after a certain character with selenium in python

Question:

what i’m actually trying to do is to download, store and recognize which images are before the " + " and which are after that simbol.

Moreover the images that i’m trying to download and store are dynamics, meaning that the numbers of src that are before and after the " + " can change.

enter image description here This is the HTML in question.

I’m actually able to download all the images that are inside that h3 but in this way i cannot recognize what are the images that are before the + simbol.

Anyone who has any idea would be really appreciated.

Asked By: Rodhad

||

Answers:

I achieved this searching for the " + " simbol and then from there search all the images that are before and after using the ‘preceding-sibling’ and ‘following-sibling’.

images_before_plus = driver.find_elements(By.XPATH, "//h3/text()[2]/preceding-sibling::img")
images_after_plus = driver.find_elements(By.XPATH, "//h3/text()[2]/following-sibling::img")

Hope this could help someone else.

Answered By: Rodhad