Correct path for =IMPORTXML on Google Sheets - google-sheets

This URL: https://www.screwfix.com/p/makita-jr3050t-2-1010w-reciprocating-saw-240v/27338
Trying to use IMPORTXML on google Sheets to pull in the price (119.99 as of today)
Using the following formula:
(via Google Developer Tab, right-click Copy XPath)
=IMPORTXML(https://www.screwfix.com/p/makita-jr3050t-2-1010w-reciprocating-saw-240v/27338, "//*[#id='product_price']/text()")
Or
=IMPORTXML("https://www.screwfix.com/p/makita-jr3050t-2-1010w-reciprocating-saw-240v/27338","//meta[#itemprop='price']/#content")
Or
=importxml(https://www.screwfix.com/p/makita-jr3050t-2-1010w-reciprocating-saw-240v/27338, "//div[#class='pr__price']")
Plus a few other variations - Unfortunatley, they all come out as #N/A
Can anyone help me find the correct path?

It seems that in this case, when the URL is retrieved by IMPORTXML(), most values are included in head. When I tried this URL, body retrieved by IMPORTXML() was empty. So how about this workaround?
=REGEXEXTRACT(IMPORTXML(A1,"//head/*"),"(\d.+)INC")
Please put the URL of https://www.screwfix.com/p/makita-jr3050t-2-1010w-reciprocating-saw-240v/27338 to the cell "A1" and put the formula to other cell.
In this workaround, the value you want is retrieved from the values retrieved from head.
Result:
Note:
I'm not sure whether this formula can be used for other URL. If you want to use this for other URL, please confirm the values and set the xpath and regex.
If you use Google Apps Script, I think that the value can be retrieved from the body of URL.
If this was not what you want, I'm sorry.

Related

ImportXML Function on Google Sheets

I'm having a tough time pulling info in on Google Sheets using the ImportXML function. I want to pull in the price of a crypto coin so that I have a real-time feed. The link that I'm hoping to pull from is:
https://www.dextools.io/app/uniswap/pair-explorer/0x40f0e70a7d565985b967bcdb0ba5801994fc2e80
I've tried out a lot of different formulas and keep getting an #N/A or an error. Some of the ones I've tried:
Copy XPATH fully:
=IMPORTXML("https://www.dextools.io/app/uniswap/pair-explorer/0x40f0e70a7d565985b967bcdb0ba5801994fc2e80","/html/body/app-root/div[3]/div/main/app-uniswap/div/app-pairexplorer/app-layout/div/div/div[2]/div[2]/ul/li[2]/span")
Shortened XPATH (also tried deleting the second backslash before 'li' but that didn't work):
=IMPORTXML("https://www.dextools.io/app/uniswap/pair-explorer/0x40f0e70a7d565985b967bcdb0ba5801994fc2e80","//li[2]/span")
Include class:
=IMPORTXML("https://www.dextools.io/app/uniswap/pair-explorer/0x40f0e70a7d565985b967bcdb0ba5801994fc2e80","//li[2]/span[#class='ng-tns-c93-2 ng-star-inserted']")
Does anyone have thoughts? Thanks!
upon disabling JavaScript the site is empty = can't be scraped by Google Sheets by any import formula.
To avoid the problem above, consider using a proper API service that gives you easy access to the data.
For instance you could get Zero price in USD using
=IMPORTDATA("https://cryptoprices.cc/ZERO/")
If you need it in comparison to ETH you could try doing it by hand
=IMPORTDATA("https://cryptoprices.cc/ZERO/")/=IMPORTDATA("https://cryptoprices.cc/ETH/")
Or use a more advanced API such as CoinGecko's
https://www.coingecko.com/en/api

Google Sheets importXML Returns Empty Value

Im trying to scrape this website (https://kamadan.gwtoolbox.com/) with google sheets for material costs for a game that I play. There are two tables; "Common Materials" and "Rare Materials" in a drop down in the top right corner. I am trying to pull the values for both as the prices update. I copied the full Xpath and used the function below in an empty cell on a sheet.
=importxml("https://kamadan.gwtoolbox.com/","/html/body/div[2]/div[1]/div/div[2]/table/tbody")
This returns a #N/A error saying it is returning an empty value.
I also tried it with the regular xpath...
=importxml("https://kamadan.gwtoolbox.com/","//*[#id='trader-overlay-items']")
Which just returns a blank cell. I have also tried both methods using the inspect function through chrome on the ancestors and children they return either of the two errors above.
Sorry if this is a really easy one. I am not familiar at all with Xpaths or html. I mostly dabble in VBA in excel.
Answer:
IMPORTXML can not retrieve data which is populated by a script, and so using this formula to retrieve data from this table is not possible to do.
More Information:
As you've already mentioned, you can attempt to get the data directly from the table using:
=IMPORTXML("https://kamadan.gwtoolbox.com/","//table[#id='trader-overlay-items']")
Which just gets a blank cell.
I went a step further and tried to reverse-engineer this by calling IMPORTXML on the HTML elements on the page in steps:
=IMPORTXML("https://kamadan.gwtoolbox.com/","html")
=IMPORTXML("https://kamadan.gwtoolbox.com/","html/body")
=IMPORTXML("https://kamadan.gwtoolbox.com/","html/body/div[1]")
=IMPORTXML("https://kamadan.gwtoolbox.com/","html/body/div[1]/div[0]")
...
html/body/div[1]/div[0] is the first path which gives no imported content, and we can see from importing html/body that the full body does not contain the imformation and only a template of it - in cell B1 we have references to 'Common materials' and 'Rare materials':
And in D1 we start to see JavaScript and JSON objects which are not called by IMPORTXML and so the results of which can not be retrieved:
As you can see if you disable JavaScript on the site, almost nothing is actually rendered and so can't be obtained using IMPORTXML:
References:
IMPORTXML - Docs Editors Help

How to use ImportXML to extract text within <span> with multiple classes?

I'm using Google spreadsheet's ImportXML function, trying to fetch member counts from discordapp.com's invite link so that I can keep track on multiple servers' size and growth. The desired text is inside a span inside other divs. From what I've read, I'd think my code would work, but the error says content is empty. See details below:
My attempted code:
=ImportXML("https://discordapp.com/invite/steam","//span[#class='pillMessage-1btqlx medium-zmzTW- size16-14cGz5 height20-mO2eIN']")
Expected: Cell filled with current count, "24,013 Members".
Preferably: Cell filled with value 24013.
Actually: Cell: #N/A & Hovering: Error Imported content is empty.
How can I fix it to fetch the server's member count?
How about this answer?
It seems that at the site, the value like 24,013 is shown by the script. So the value cannot be directly retrieved by IMPORTXML(). But when I saw the HTML, it was found that the value is included in the metadata of HTML. In this answer, as a workaround, the value is retrieved from the metadata. Please think of this as just one of several answers.
Modified formula:
=VALUE(REGEXEXTRACT(IMPORTXML(A1,"//meta[3]/#content"),"hang out with ([0-9,]+) "))
The url of https://discordapp.com/invite/steam is put to the cell "A1".
Content of metadata is retrieved using IMPORTXML().
In this case, I used //meta[3]/#content as the xpath.
The value is retrieved using REGEXEXTRACT().
The value is converted to the number using VALUE().
Result:
When I tried above formula, 24018 was retrieved.
References:
IMPORTXML
REGEXEXTRACT
VALUE
If I misunderstood your question and this was not the result you want, I apologize.

extract data from Google spread sheets using imcaro

I'm trying to extract a cell value from a Google spreadsheet using imacro script.
This is the spread sheet I'm working on.
And I need to get the Cell 'A1' value.
Below is my try, and it is not working.
TAG POS=2 TYPE=A ATTR=TXT:https://www.ebay.com* EXTRACT=TXT
Please help.
One of the possible (simplest) ways is to use Google Query Language for requesting necessary data and extract them afterwards. Something like this:
URL GOTO=https://docs.google.com/spreadsheets/d/13akuXU0cp047_6VFdtUgdn2fKfhPilF_hPHrnTNV164/gviz/tq?tqx=out:html&tq=select%20A%20limit%201
TAG XPATH="//tr[last()]/td" EXTRACT=TXT
Keep in mind that your spreadsheet must be shared in this case.

Google Sheet cell value original input 2-1-0 shows as 2-1-2000

I am scraping the information from another website to Google Spreadsheets using js formula and getting back mismatching value data (2-1-0 shows as 2-1-2000)
Please could someone explain me in details how it works and how to fix it?
Google Sheets spreadsheet engine interpret 2-1-0 as a date and display it accordingly to the default format settings for dates considering the spreadsheet language and regional settings.
If the original value it's not a date, you could make that a Google Apps Script function using UrlFetchApp add an apostrophe (') as a prefix for those values: '2-1-0.

Resources