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
Related
I have a Google Doc, within which I linked a Sheet. So, a table and/or a chart, that updates when the corresponding range in the linked spreadsheet updates.
Now, I want to make a copy of this document, so that the copy is linked to a (new) google sheet, which also is a copy of the original google sheet.
My first idea was using the Docs API to update some sort of reference, but it seems it's not possible to update an .. EmbeddedObject. I also tried using a Google Apps Script, but there I could also not figure out how to do this. I looked at a few more things, like creating a new doc using the Doc API, but I can't pass the inlineObjects or positionedObjects1, and apparently can't insert it afterwards either.
Did I just miss something? How can I make a duplicate of a Doc and a linked Sheet?
Any tricks, as hacky as they may seem, are very welcome!
1 While documents.create does accept both in the request body, the reference says "[...]any provided content, are ignored." (and indeed it is)
I am a little bit new to Google Script so apologies if my question is silly. I have the following user scenario:
- on a monthly basis I get standard file from on of my departments
- I save the file on Google Drive and automatically copy certain information to my Sheets that I use to analyse this information
- I finished the code that does the copy, selection, etc.
I am struggling with the first piece - some sort of SelectBox that I would use to select source file. I can write code that will search Google Drive and display potential files, display them in ListBox, but maybe there is other way (the simpler the better). What would you recommend here?
Google has nice Box that shows up when you try to copy sheet into other Sheets document, but it seems not to be avaialble for Script.
Any help is much appreciated.
I know how to important HTML Data into Google Sheets so that it displays, but I am trying to figure out if it is possible to also copy a web data entry form into Google Sheets, so that you can enter values, which would then be presented by the data.
I am trying to import this calculator into Google Sheets so that I can work with the real time values.
http://www.coinwarz.com/calculators/ethereum-mining-calculator
Any ideas about how I can do this?
I am not aware of any way to import the actual HTML form into Google Sheets. However, here is how I would do it:
I would open Chrome and find the outgoing POST request that occurs when you press the green Calculate button on that site.
I would use Postman to test and create the request and see if it works.
Using Google Apps Script, you can issue HTTP requests. I would re-construct the request being sent in Google Apps Script.
To make it look nicer, you can re-construct the calculator in your Google Sheet. You can recreate the calculator's input buttons as cells and then fetch those cells in your GAS code (like, hash_rate_cell.getValue()):
In this link answer in line 6, how to identify how many getElement("div") and getElements("div")[number] should be captured from a URL.
This is the URL from where I am looking to capture the table.
You may want to look into using import.io, which is a tool specifically for extracting tabular data from web pages, and which has an Apps Script integration.
another example could be to pull the table into Sheets and the access the data from within the Sheets. For example:
=importhtml("http://www.tradingeconomics.com/zambia/rating","table",1)
This pulls the first table on the particular webpage into the sheet.
After reading up a lot on the Google Spreadsheet API I have come to the conclusion that formatting (such as merging cells, changing fonts etc) is only available throught the Apps scripts.
Since we need to create and fill the spreadsheets with data programatically using Java on the back-end I guess I need to somehow either;
link the new sheet to a Apps script that trigger on-load or
create a Apps script that creates the spreadsheet for me.
Anyone knows?
If you want to just "create" the spreadsheet, you don't need a script to load whenever it spreadsheet is opened. It's probably easier to develop a script that runs once and create the spreadsheet for you.
Another tip is to have a template file that you can copy with most of the formatting (if not all) already there. Possibly pending just little things that are related to the real data the new spreadsheet will have.
Edit to answer the question in the title.
No, you can not add a script to an existing spreadsheet programatically, only manually. What you can do is previously set up a template spreadsheet with a script in it and create new spreadsheets by copying this template.
(answering the comment)
You can run a script programatically, but not upload it. To run a script you can deploy it as a web-app and call its url with either a http get or post (will call its doGet or doPost functions, that you must have declared). Also, you could set this script to run on form submit of any spreadsheet-form and just submit a set of answers to this form. At last (that I can think of now) you could just add the script as a library in another Apps Script and call it directly.
(Aug 2016) There is no way programmatic way to link a Google Sheet and Apps Script code other than manually. Based on what it seems you want ("create and fill the spreadsheets with data programatically using Java"), you can now do it without Apps Script.
TL;DR: Above, #Henrique has answered multiple questions and even questions that weren't asked! The good news is that today, we have more answers representing alternate possible solutions to what you're seeking.
It's now possible to "upload" Apps Script code programmatically with the
import/export system, say with Eclipse since you're a Java developer (2013 announcement).
I agree with Henrique's suggestion that if you create a spreadsheet
template, i.e., Excel file, you can use the Google Drive API to
programmatically import/create identical Google Sheets with all your
desired formatting.
"Formatting (such as merging cells, changing
fonts etc)" can now be done outside of Apps Script, as there is a
"new" Google Sheets API v4 (not GData).
In order to use the new API, you need to get the Google APIs Client Library for Java and use the latest Sheets API, which is much more powerful and flexible than any previous API. Here's one code sample to help get you started. If you're not "allergic" to Python, I also made a video with a different, slightly longer example introducing the new API and gave a deeper dive into its code via a blogpost that you can learn from.
Note the v4 API allows you to create spreadsheets & sheets, upload & download data, as well as, in the general sense, programmatically access a Sheet as if you were using the user interface (create frozen rows, perform cell formatting, resizing rows/columns, adding pivot tables, creating charts, etc.), but to perform file-level access such as uploads & downloads, imports & exports (same as uploads & downloads but conversion to/from Google Apps formats), you would use the Drive API instead.