0

I need import prices from web and Use importxml function in Google Sheets - but getting Importxml error could not fetch url. I found another solution here: Google Sheet use Importxml error could not fetch url

But I have problem how to edit this to my needs.

I need load different prices from different links. E.g in column C its list of link, which I want to import price to Google Sheets (Price cant be only from Tarkov market - but I use link which was used in link where I found solution - For example import some prices from CoinMarketCap.com or another exchange website).

Example of URLs and prices

Mike F
  • 1

1 Answers1

0

Solution

In order to make the formula you found more dynamic you should pass the URL as a parameter.

You can change it to something like this:

/** 
* @customfunction
*/
function getTarkovMarketPrice(url) {
  const html = UrlFetchApp.fetch(url).getContentText();
  return html.match(/price:(.+?)<\/title>/)[1].trim();
}

Note: This function will retrieve the price from this specific platform you will have to implement your own parsing logic for different pages.

You can then use the function in your Spreadsheet:

,__________________________________________________________________________,
|                       A                      |             B             | 
|----------------------------------------------+---------------------------|
| https://tarkov-market.com/item/Pack_of_sugar | =getTarkovMarketPrice(A1) |
|----------------------------------------------+---------------------------|

Referece

Custom Functions

Alessandro
  • 2,848
  • 1
  • 8
  • 16