Google Maps Xpath using Google Spreadsheet IMPORTXML - google-maps

I am trying to use Pull data from google maps results using IMPORTXML function in google spreadsheet but I am getting error #N/A
=importxml(http://maps.google.com/maps?q=cosmetic+surgeon+NEAR+New+York%2C+NY%2C+United+States&output=classic&dg=ntvb,"//div[#class='name lname'])
or
=importxml(http://maps.google.com/maps?q=cosmetic+surgeon+NEAR+New+York%2C+NY%2C+United+States&output=classic&dg=ntvb,//SPAN[#class='pp-place-title'])
but nothing is working.. Any thoughts???
Thanks

If you're going to give importxml literal strings as arguments, they need to be double-quoted:
=importxml("http://maps.google.com/maps?q=cosmetic+surgeon+NEAR+New+York%2C+NY%2C+United+States&output=classic&dg=ntvb", "//div[#class='name lname']")

Related

Reverse Geocode using API Key for Google Sheet

I need to get a working JSON script for Google Sheet to get "FOMATTED_ADDRESS" for more than 5,000 GPS coordinates.
I am no expert in JSON nor Javascipt.. I only need a simple script that works in Sheet. All I have tried I get an error in the result of the query..
Can somebody help?
Thanks!

IF formula is getting error in Google Sheets Script

I tried IF formula in Google Sheets script like
=IF(D:D=False, "PAID", "NOT PAID")
but it's showing error.
Any other substitute formula for this condition?
What you are looking for is an array formula, which has nothing to do with Google Apps Script.
=ArrayFormula(if(D2:D=false,"Paid","Not Paid"))

Google Sheet use Importxml error could not fetch url [duplicate]

This question already has answers here:
Scraping data to Google Sheets from a website that uses JavaScript
(2 answers)
Closed last month.
I want to get price data on this website (https://tarkov-market.com/item/Pack_of_sugar)
But it doesn't work
=IMPORTXML("https://tarkov-market.com/item/Pack_of_sugar","//*[#id='__layout']/div/div[1]/div/div[4]/div[1]/div[2]/div[1]/div[2]")
You want to retrieve the price like 55,500₽ from the URL of https://tarkov-market.com/item/Pack_of_sugar and put to a cell on Google Spreadsheet.
I could understand like this. If my understanding is correct, how about this answer?
Issue and workaround:
Unfortunately, IMPORTXML cannot be used for this situation. Because IMPORTXML is used like =IMPORTXML("https://tarkov-market.com/item/Pack_of_sugar","//*"), an error like the value cannot be retrieved from the URL occurs. So in this case, as a workaround, I would like to propose to use Google Apps Script as a custom function. When Google Apps Script is used, the value can be retrieved.
Sample script:
Please copy and paste the following script to the container-bound script of the Spreadsheet. And please put =sampleFormula() to a cell. By this, the value can be put to the cell.
function sampleFormula() {
const url = "https://tarkov-market.com/item/Pack_of_sugar";
const html = UrlFetchApp.fetch(url).getContentText();
return html.match(/price:(.+?)<\/title>/)[1].trim();
}
Result:
Note:
This script is for your question. So when this script is used for other URL and scenes, an error might occur. Please be careful this.
References:
Custom Functions in Google Sheets
Class UrlFetchApp

Google Spreadsheets ImportXML and XPath

I'm trying to extract rate data from below URL by using Google Spreadsheets:
used importXML() function with following XPath sting:
=IMPORTXML("https://www.superrichthailand.com/#!/en/exchange","//span[#class=""ng-binding""]")
Which, it should return every entry in the pages all the rate but return empty.
Google Sheets IMPORTXML can't access dynamically generated data, only the source code in the file referred by the URL.

How to use ImportXML in a Google Script?

Scenario:
I am trying to use Google spreadsheet to do something like this:
I've a set of Blog URL's (more than 50) for which I want to fetch title
Currently I am using the formula: ImportXML(A2,"//h1[#class='entry-title']" )
The Problem w/ this approach is that ImportXML calls are limited to 50 per spreadsheet and I've more than 50.
I browsed/searched - found out that we can use ImportXML calls in google apps script but did not found any example.
I found this: https://developers.google.com/apps-script/articles/XML_tutorial but I was hoping to use ImportXML function.
Can anyone describe or point to a resource where they have used ImportXML in a google apps script? Thanks!
I would use a few spreadsheets, then pull the results together into a master spreadsheet, or are you doing >1000 or so. If you have lots, the XML_tutorial link you have is the place to start.
But last time I checked, google-apps-script does not support google spreadsheet functions, if I remember, the feature request to support all spreadsheet functions in GAS was rejected.