Search code examples
google-sheets

What is the right input to complete this =ImportXML in Google Sheets


I am trying to automate pulling number of review and rating from Trip Advisor... how would I find the right xpath query to pull? I have been trying to pull and have been getting errors or just the headers.

=IMPORTXML("https://www.tripadvisor.com/Hotel_Review-g57653-d15065834-Reviews-Hampton_Inn_Suites_Culpeper-Culpeper_Virginia.html","/html/body/div[2]/div[2]/div[2]/div[4]/div/div/div[4]/div/div/div/div/div[2]/div[1]/div[1]/span","en_US")

I know the xpath is not the one represented above... if anyone knows what the best input would be to get "120 review" and "4.5/5", it'd be greatly appreciated!

=IMPORTXML("https://www.tripadvisor.com/Hotel_Review-g57653-d15065834-Reviews-Hampton_Inn_Suites_Culpeper-Culpeper_Virginia.html","/html/body/div[2]/div[2]/div[2]/div[4]/div/div/div[4]/div/div/div/div/div[2]/div[1]/div[1]/span","en_US")

I know the xpath is not the one represented above... if anyone knows what the best input would be to get "120 review" and "4.5/5", it'd be greatly appreciated!


Solution

  • You may try:

    Rating: =importxml(A1,"//*[@id='ABOUT_TAB']/div[2]/div[1]/div[1]/span[1]")&"/5"

    Reviews: =join(,importxml(A1,"//*[@id='ABOUT_TAB']/div[2]/div[1]/div[1]/a[1]/span[2]"))

    enter image description here