Why am I receiving "Could not fetch URL" error on Google Sheets Import XML? - json

New here, and still trying to wrap my mind around this importXML tool in Google Sheets. Seem to be able to get it to work on certain websites, but when data is deeply embedded in code, I struggle.
Goal: To pull in weight of items listed on bricklink.com to a Google Sheet.
Link to my Google Sheet: https://docs.google.com/spreadsheets/d/1_vhCkEJXofxMj1Cg117RgPJSFTqPF0ijo_f60mDR6MU/edit?usp=sharing
When I copy the xpath from the source code on the site, I'm given this value: //*[#id="item-weight-info"].
The existing fomula I have is: =IMPORTXML(D2,"//*[#id='item-weight-info']")
D2 Contains the web address where it concatenates the website + the item number.
Error I'm receiving is: "Could not fetch url: https://www.bricklink.com/v2/catalog/catalogitem.page?S=21318"
I did come across a potential JSON solution, set up a JSON function in the sheet, but have never written a script before. Tried to copy a script, and tweak as needed, but still no luck.
Is there an easier way to do this that I'm overlooking?
Any guidance or suggestions would be greatly appreciated. Thank you for your time!

Related

Script to get a GooglePhoto using filename stored in GoogleSheets

I have a Googlesheets that has in one of its columns the filename (as "filename.jpg") of pictures stored in GooglePhotos (and/or Google Drive). I would like to have a script that would show me the selected picture when I click on a given cell of that particular column.
I'm quite familiar with Googlesheets Scripts and have looked at Google Photos API but don't know where to start.
Has anyone developed something like this and is willing to share? Any hints will be very much appreciated.
Many thanks in advance
I have a similar solution. You have to start from Browser API and this existing repo https://github.com/gsuitedevs/apps-script-samples/tree/master/docs/dialog2sidebar
But before that you have to realize the next flow:
Get a string
Try to search the file with this string
Return the file or undefined

Google Sheets - UrlFetchApp/ GetContentText - working with data?

I have managed to receive HTTP response from a protected webpage by using UrlFetchApp and passing credentials/cookie etc. This correctly returns the data and I have been able to convert to a blob and download as a text file.
However, what I want to do is extract the relevant table from the HTML file, in exactly the same way as the ImportHTML() function works in google sheets. Can anyone give me some hints on this? I have tried parsing using xml service but it doesn't like the data, i'm hoping there is a simpler way?
Cheers

Custom formula returning #NAME when Google Sheets is published to web

I'm not much of a programmer, but I managed to write a Google Sheets script that sorts an array, filters out specified values, and returns the new array. It works great.
However, when I publish the output page to the web, the link will only successfully show the output if I have the back end sheet open. As soon as I close it, the publish page turns up #NAME.
Presumably there is some restriction as to the availability of custom scripts. I assumed the output would just grab the text, but I suppose it's trying to run it and can't without someone being logged in?
Anyways - is there some way around this?
Thanks
Edit: Did a little further reading and found out that this might be a situation where "script as web app" might be the requirement. As a novice, this is a little over my head and I'd appreciate any advice.
I also tested to make sure IMPORTRANGE() as a source for this data wasn't the issue, and though it may cause other problems once I get the #name issue resolved, it does not appear to be at fault here specifically since the same thing happens with local data.
Yes, as you've stated, script as web app might be the requirement. You may also want to check this documentation regarding Custom Functions in Google Sheets. Just be noted that a script can be published as a web app if it meets these requirements:
It contains a doGet(e) or doPost(e) function.
The function returns an HTML service HtmlOutput object or a Content service TextOutput object.
Hope this helps!

IMPORTxml on google sheets

Trying to make a spreadsheet on google sheets that scrapes data from a site.
I'm trying to get the sell price of items from rsbuddy exchange, eg:
https://rsbuddy.com/exchange/?id=1745
I have the code on google sheets as:
=IMPORTxml("https://rsbuddy.com/exchange/?id=1745","//*[#id='sell-price']")
But instead of showing me 1734gp it comes up as --- on the sheet.
I've tried adding /text() at the end of the query for the importxml but it doesn't change anything.
I'm guessing the solution is something similar?
I don't believe you can do it with xpath because it's populated dynamically. If you view the full source, you're getting what is there. It's literally ---
You can see the source data here which is in JSON and looks like it's tied to the page url id. Google sheets doesn't natively support json but this good person wrote a script and it seems to work well in my example sheet.
You'll need to do it via JSON, though you can't importJSON natively through Google Sheets. If you add this library as code to your sheet (via the script editor) then you can you can use =IMPORTJSON (with different parameters) to get the data back that you need.
http://blog.fastfedora.com/projects/import-json

How do you retrieve data from a Google Docs Spreadsheet?

I found this wonderful example of pulling data from a Google spreadsheet in JSON:
http://code.google.com/apis/gdata/samples/spreadsheet_sample.html
However, I can't seem to get it to work for a spreadsheet I created. I've made the doc public and published it, and tried every possible tweak on the key and sheet "name". Has anyone successfully used this? I've seen the Zend GData library, but would rather use JSON.
Thanks in advance for any tips.
I tried to work with the JSON feed a few months ago and I remember having to jiggle the handle a little to get the feed URL to work. I don't recall exactly what I did, but the bigger problem is that once you get it working the feed itself is kind of a mess.
I found that a much better solution (for my purposes, at least) was to use the CSV feed and then convert that to JSON on the server. I actually wrote a blog post outlining the steps a few weeks ago:
http://www.ravelrumba.com/blog/json-google-spreadsheets/
Google Spreadsheet as JSON can be done using Google Apps Script !
In Google Spreadsheet go to Tools > Scripts > Script Editor
Insert this code and hit the play button, use generated URL for generating JSON.
function getValues() {
var range = SpreadsheetApp.getActiveSheet().getDataRange();
var json = Utilities.jsonStringify(range.getValues())
Browser.msgBox(json);
}​
also give it a try for Simple example of retrieving JSON feeds from Spreadsheets Data API