0

So, I'm trying to use the ImportXML function in Google sheets to scrape some data from a website (https://www.cargurus.com/Cars/m-Bob-Johnson-Certified-Collection-sp402449), and I'm having trouble finding a path that works. This is the section I'm looking to pull. Section of filter results

I've tried using Chromes Inspect Element and using Copy X-path, Which gives me //*[@id="ratingFilter_ContainerId"]/div and returns #NA

I've used a Chrome plug-in called Scraper, which gives me //div[13]/div/div[2]/div[2]/div/label and returns #NA

I've even tried going through the code and making as direct a path as I could from scratch and came up with //body/div[1]/div[1]/main/div[1]/div[1]/div[11]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[3]/div[1]/div[4]/div[2]/div[13]/div[1]/div[2]/div[2]/div which also return #NA

So any tips for finding an accurate XPath would really be appreciated.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Tarq12
  • 1

1 Answers1

0

The expression

//*[@id="ratingFilter_ContainerId"]

executed on a fetched document selects a div element two levels above the one you show.
When extended by another step subexpression:

//*[@id="ratingFilter_ContainerId"]/div

it selects the div which contains the 'Deal Ratings' caption with the '(clear)' link at the right side, and the options list you need.

What you are interested in is rather

$fetched-document/descendant::div[@id="ratingFilter_OptionListContainer"]

EDIT

BTW, are you sure you fetch the page properly? When I load it into my browser, the page seems to load some additional data, which is noted with a 'Loading listings...' splash. Maybe you're trying to execute your query on an incomplete page...?

CiaPan
  • 9,381
  • 2
  • 21
  • 35