this post was submitted on 02 Feb 2024
15 points (85.7% liked)

Python

6343 readers
11 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
 

I want to scrape a website using python selenium however every time it gives different id to same html element. I don't know how to circumvent it.

maybe XPATH is my saviour? but I don't know how reliable it is.

top 3 comments
sorted by: hot top controversial new old
[–] bjorney@lemmy.ca 17 points 9 months ago (2 children)

You should be able to search by class name, find something salient in the Dom tree nearby and step over/up/down to your desired element

[–] sbv@sh.itjust.works 5 points 9 months ago

yup. Use the structure of the document.

If that isn't possible, use the visual representation.

[–] SatouKazuma@lemmy.world 4 points 9 months ago

Yup. CSS selectors are great for this very reason.