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
Related
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!
I need to fetch a simple document template file (.doc) from google docs (or drive), then fill in the missing details and save the document as new file into the cloud.
Could someone advise on how to achieve this using the Google Docs API so this could be done within bespoke environment?
thanks in advance
If I understand you correctly, you want to programmatically:
Retrieve a document from Drive.
Edit this document while keeping the original one unmodified.
Save this new document.
You have to follow these steps:
Use Files.copy from Drive API to copy the file you want to edit. To achieve this, you have to provide the id of the original file as a request parameter. As a response you will get a File resource corresponding to the copy you created. Retrieve the file id from this response.
Update this new file using batchUpdate from Docs API. For that you will need to (1) provide the file id you retrieved in the previous step as a parameter and (2) provide the changes you want to make using the requests parameter (an array of all the changes you want to make) in the request body (check the links I attach to know exactly how should your requests parameter be like - I would like to be more specific here, but I don't know how exactly do you want to modify the document).
Obviously, there is no need to save the modified document, this is done automatically when the file is modified.
I hope this is of any help to you.
I am wondering if anyone can give me an example on how to gather data from a JSON file, and import it into a single cell in google sheets? It does not need to be formatted or copied to multiple cells, it simply needs to take the entire contents of the JSON and copy it into a single cell. The file I am working with is also a local file. Can anyone shed some light? It does not necessarily need to use google apps script, if a python script or anything similar could do the same thing that would be ok
First of all, Google Sheets cannot access your local files. It's a web application, so any external data it gets must be accessible from the Internet.
If your goal is simply to put the contents of a web-accessible JSON file in a single cell, the following custom function will do the job:
function import(url) {
return UrlFetchApp.fetch(url).getContentText();
}
This simply grabs whatever page you point at, and crams its contents in a cell. Example: =import("http://xkcd.com/info.0.json")
If you do decide to parse JSON, be advised there isn't anything suitable built into Google Sheets at present. The project importJSON by Trevor Lohrbeer may be helpful.
You can also use an extension of "API CONNECTOR" for free in the google sheets and just paste the url of the json file you need to import.
here is the link to the API Connector extension
https://workspace.google.com/marketplace/app/api_connector/95804724197
here is how to perform it.
https://www.benlcollins.com/apps-script/api-tutorial-for-beginners/
I'm trying to link Google Spreadsheet to twitter- have them talk to eachother - and I'm trying to use JSON.
(Trello and Google calendar are another idea with JSON)
from what I've gathered, you're supposed to use Utilities.JSONParse() for this data. I'm not sure what goes in the brackets to create a JSON object. I keep getting an invalid JSON string when my basic code runs;
function myFunction() {
var j = UrlFetchApp.fetch("https://api.trello.com/1/organizations/fogcreek?key=727f13bf79cfa362db49b79eb8c56c94");
Utilities.jsonParse(j);
}
So... examples/help on how to read JSON objects in a google spreadsheet would be great!
Thanks.
This is a Google Docs spreadsheet a very clever guy has created which imports from Trello using Google Apps script:
http://www.littlebluemonkey.com/blog/online-scrum-tools-part-4-trello-backup/
It takes the JSON data and translates it, so looking at his code may help you with twitter json import.
There's also another clever guy who explains how he's done something similar with Trello:
http://www.kevinpelgrims.com/blog/2012/03/05/project-progress-tracking-with-google-docs-and-trello/
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