Daniel Almeida
Daniel Almeida

Reputation: 13

How to find a custom selector inside a web element using X-path or other method?

I am working on a web scraper on Python using selenium and I want to scrape a specific element (data-car-id) from a div which I can actually locate using the Xpath

The id I want to scrape

Upvotes: 1

Views: 82

Answers (1)

Rohan Shah
Rohan Shah

Reputation: 489

First you must find the element using whatever method you would like, xpath, id, class_name, etc. Next, just use the .get_attribute method, it should look like this:

element = browse.find_element_by_class_name("listing-item")
element.get_attribute('data-car-id')

Upvotes: 1

Related Questions