How to grab web data into Numbers sheet

Hi. I need to insert data from webpage into table cells in Numbers. Basically I need to get some cryptocurrencies rates into my sheet, and it should update in real time. Numbers support only BTC/USD so it is definitely not enough. Excel can "Get external data" from webpage but it is much more comfortable to use Numbers. Does any solution exists for Numbers?

iMac, iOS 11.0.3

Posted on Oct 21, 2017 12:49 AM

Reply
Question marked as ⚠️ Top-ranking reply

Posted on Oct 31, 2017 5:32 AM

Below is a simple script that grabs the last prices from the linked website and populates a Numbers table.


  1. Copy-paste into Script Editor (in Applications > Utilities).
  2. In the first three lines change sheet, table name and target cell to match your setup.
  3. With the Numbers document open, click the triangle 'Run' button in Script Editor.


(If "nothing happens" make sure Script Editor.app is checked at System Preferences > Security & Privacy > Privacy > Accessibility).


That's it! You should be up and running in about two minutes. If you update prices often then you can put the script in the Script menu as explained here. (You can also attach a keyboard shortcut by placing it in an Automator Service.)


SG


-- change values between "" in the first three lines to match your setup

set mySheetName to "Sheet 1"

set myTableName to "Coin Prices"

set tgtCell to "A2"


set theHtml to do shell script "curl -s " & quoted form of "https://www.worldcoinindex.com"

set text item delimiters to {"<tbody>", "</tbody>"}

set tableContents to theHtml'stext item 2 # item 2 is the body of the price table

set text item delimiters to {"<h2>"} # site uses new h2 for each currency

set tableChunks to tableContents'stext items 2 thru -1

set pasteStr to ""

repeat with aChunk in tableChunks

set text item delimiters to "><span>$ </span><span class=\"span\">"

tell aChunk's text item 1 to set {theSymbol, thePrice} to {first word, last word}

set pasteStr to pasteStr & theSymbol & tab & thePrice & return

end repeat

set the clipboard topasteStr



tell application "Numbers"

tell front document

tell sheetmySheetName to tell tablemyTableName


activate

set selection range to rangetgtCell

delay 0.3

tell application "System Events" to keystroke "v" using {option down, shift down, command down}

end tell

end tell

end tell

11 replies
Sort By: 
Question marked as ⚠️ Top-ranking reply

Oct 31, 2017 5:32 AM in response to mr.bodich

Below is a simple script that grabs the last prices from the linked website and populates a Numbers table.


  1. Copy-paste into Script Editor (in Applications > Utilities).
  2. In the first three lines change sheet, table name and target cell to match your setup.
  3. With the Numbers document open, click the triangle 'Run' button in Script Editor.


(If "nothing happens" make sure Script Editor.app is checked at System Preferences > Security & Privacy > Privacy > Accessibility).


That's it! You should be up and running in about two minutes. If you update prices often then you can put the script in the Script menu as explained here. (You can also attach a keyboard shortcut by placing it in an Automator Service.)


SG


-- change values between "" in the first three lines to match your setup

set mySheetName to "Sheet 1"

set myTableName to "Coin Prices"

set tgtCell to "A2"


set theHtml to do shell script "curl -s " & quoted form of "https://www.worldcoinindex.com"

set text item delimiters to {"<tbody>", "</tbody>"}

set tableContents to theHtml'stext item 2 # item 2 is the body of the price table

set text item delimiters to {"<h2>"} # site uses new h2 for each currency

set tableChunks to tableContents'stext items 2 thru -1

set pasteStr to ""

repeat with aChunk in tableChunks

set text item delimiters to "><span>$ </span><span class=\"span\">"

tell aChunk's text item 1 to set {theSymbol, thePrice} to {first word, last word}

set pasteStr to pasteStr & theSymbol & tab & thePrice & return

end repeat

set the clipboard topasteStr



tell application "Numbers"

tell front document

tell sheetmySheetName to tell tablemyTableName


activate

set selection range to rangetgtCell

delay 0.3

tell application "System Events" to keystroke "v" using {option down, shift down, command down}

end tell

end tell

end tell

Reply

Oct 21, 2017 6:24 PM in response to mr.bodich

This is how I get stockmarket up to date data into my numbers sheets.


1. Open a Google Drive account, then create a Google docs spreadsheet.


2. In column one, I type, say, BHP.ax (for the Aussie market)


3. Setup the following columns to give you the information you need. I tried to paste an example for you but was not able to do so as I'm not that clever.


4. I then cut and paste the column information into my sheet which has matching data setup.


It takes about 30 seconds for me to update the 200 or so prices and 5 movements that I need.


Hope this is helpful to you. Works for me. Yahoo has an automatic update in Numbers but I think it only updates about once per day. Unsatisfactory, in my case.



User uploaded fileUser uploaded file

Reply

Oct 21, 2017 4:00 PM in response to mr.bodich

mr.bodich wrote:


For example from this website https://www.worldcoinindex.com/

But looks like very complex solution, I need to learn several days how Apple Script works, never did that.


Running a script (as opposed to writing one) usually takes the click of a mouse or a choice from the menu. That takes less than a minute, not days.


However, for that particular site, have you considered just selecting the table with prices, type command-c to copy, clicking once in a Numbers cell and Edit > Paste and Match Style?


The result of doing that here is:


User uploaded file


The prices are in column E. You can easily use them elsewhere in your document via VLOOKUP().


SG

Reply

Oct 21, 2017 7:13 PM in response to mr.bodich

For stock prices (as opposed to cryptocurrencies) I do believe the scripts in the linked thread are much easier than setting up formulas in Google Sheets and then copying information over from there. To update prices I just make a menu choice (because I've put the script in the Script Menu). No formulas. No Google account. Easily hundreds of price updates in a second or so.


But cryptocurrencies that aren't on Yahoo! Finance are a different matter.


SG

Reply

Oct 22, 2017 12:47 AM in response to SGIII

This script works, thank you very much! I am trying to understand how it works but confused when trying to add something like switching to main sheet after prices updated. That not works. Thanks for script, that would take weeks to learn how it works for me... Have you any great manual?))



set diary to "Diary"

tell sheetmySheetName to tell tablemyTableName

activate

set selection range to rangetgtCell

delay 0.3

tell application "System Events" to keystroke "v" using {option down, shift down, command down}

end tell

tell sheet diary

activate

end tell

Reply

Oct 22, 2017 1:50 AM in response to SGIII

I've found how to switch to target sheet, only problem is selection is clearing, but it's better than nothing.

tell sheet "Diary" to tell table "Diary"


activate

set selection range to rangetgtCell

tell application "System Events" to keystroke "a" using {shift down, command down} -- Deselect All

end tell

Have you any idea how to insert hyperlink to script inside table? To have a button "Update"...

Reply

Oct 22, 2017 7:04 AM in response to SGIII

Hi again. I think slightly understood how the script works. It takes first and last word in range. But now when I need to change it to work with https://www.worldcoinindex.com/exchange/poloniex I cannot understand how to grab several values in each string. I can grab only currency symbol, but no success with other(((

Reply

Oct 31, 2017 5:32 AM in response to mr.bodich

mr.bodich wrote:


trying to add something like switching to main sheet after prices updated.


You can do that with something like this. (In my document I named the sheet with with the retrieved prices "Prices" and the table on that sheet "Coin Prices"). You can easily change the script to match your setup.


No buttons in Numbers, but you can place the script in the menu for a quick update whenever you need. Or attach a keyboard shortcut. You can also make the script automatically run at set time intervals although I tend to think that's more trouble than it's worth.


Hope you find the posts here helpful.


SG


-- change values between "" in first three lines to match your setup

set mySheetName to "Prices"

set myTableName to "Coin Prices"

set tgtCell to "A2"


set theHtml to do shell script "curl -s " & quoted form of "https://www.worldcoinindex.com"

set text item delimiters to {"<tbody>", "</tbody>"}

set tableContents to theHtml'stext item 2 # item 2 is the body of the price table

set text item delimiters to {"<h2>"} # site uses new h2 for each currency

set tableChunks to tableContents'stext items 2 thru -1

set pasteStr to ""

repeat with aChunk in tableChunks

set text item delimiters to "><span>$ </span><span class=\"span\">"

tell aChunk's text item 1 to set {theSymbol, thePrice} to {first word, last word}

set pasteStr to pasteStr & theSymbol & tab & thePrice & return

end repeat

set the clipboard topasteStr


tell application "Numbers"

tell front document

tell active sheet to set currSheet to its name # save current location

tell sheetmySheetName to tell tablemyTableName


activate

set selection range to rangetgtCell

delay 0.3

tell application "System Events" to keystroke "v" using {option down, shift down, command down}

end tell


activate

set active sheet to sheetcurrSheet# go back to original location

end tell

end tell

Reply

Oct 22, 2017 9:09 AM in response to SGIII

Hi again. THANK YOU A LOT!!! I updated script as I need and understood something how it works. Here is the result, not it can be used for as many crypto stocks as I need, I can just add it in list variable in the beginning. Now everything is cool, thank you again! Here is last version:

-- change values between "" in the first three lines to match your setup

set exchanges to {"poloniex", "bittrex"}

repeat with exchange in exchanges

set mySheetName to "Prices"

set myTableName to exchange

set tgtCell to "B2"

set diary to "Diary"


set urlSite to "https://www.worldcoinindex.com/exchange/" & exchange

set theHtml to do shell script "curl -s " & quoted form of urlSite

set text item delimiters to {"<tbody>", "</tbody>"}

set tableContents to theHtml'stext item 2 # item 2 is the body of the price table

set text item delimiters to {"style=\"color:#000\">"} # site uses new h2 for each currency

set tableChunks to tableContents'stext items 2 thru -1

set pasteStr to ""

repeat with aChunk in tableChunks

set text item delimiters to "</td>"

set theSymbol to first word of aChunk's text item 1

set btcPrice to last word of aChunk's text item 2

set usdPrice to last word of aChunk's text item 4

set btcVolume to last word of aChunk's text item 3

set usdVolume to last word of aChunk's text item 5

set pasteStr to pasteStr & theSymbol & tab & btcPrice & tab & btcVolume & tab & usdPrice & tab & usdVolume & return

end repeat

set the clipboard topasteStr



tell application "Numbers"

tell front document

tell active sheet to set currSheet to its name

tell sheetmySheetName to tell tablemyTableName

activate

set selection range to rangetgtCell

delay 0.3

tell application "System Events" to keystroke "v" using {option down, shift down, command down}

tell application "System Events" to keystroke "a" using {shift down, command down} -- Deselect All

end tell

activate

set active sheet to sheetcurrSheet# go back to original location

end tell

end tell

end repeat

Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to grab web data into Numbers sheet

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.