Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to get data from a website into Numbers using Applescript?

Hello,

everything is the title and what I would like to achieve is simply loading the different yield curves into numbers automatically.


I followed what is this thread (https://discussions.apple.com/thread/8126136) but it doesn't work...


Any help is welcome. Thanks !


The table I would like to load is basically here:

https://www.treasury.gov/resource-center/data-chart-center/interest-rates/Pages/TextView.aspx?data=yield

Posted on Dec 6, 2018 11:24 PM

Reply
Question marked as Best reply

Posted on Dec 7, 2018 5:42 PM

Not fully automatic, but almost as simple as clicking to run a script. Uou can simply click to the left of the D in Date, hold down the "mouse" button ,and drag to select the whole table so it looks like this:



Then type command-c to copy to the clipboard, click in a cell in the destination Numbers table and command-v to paste.


The result in Numbers:



SG



5 replies
Question marked as Best reply

Dec 7, 2018 5:42 PM in response to adrienDC

Not fully automatic, but almost as simple as clicking to run a script. Uou can simply click to the left of the D in Date, hold down the "mouse" button ,and drag to select the whole table so it looks like this:



Then type command-c to copy to the clipboard, click in a cell in the destination Numbers table and command-v to paste.


The result in Numbers:



SG



Dec 9, 2018 7:25 PM in response to jaxjason

Well actually, I started with the example and the same website used initially. I only changed the 3 first row to match my setup.


Here is the original script:


-- 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

How to get data from a website into Numbers using Applescript?

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