Script Safari/DEVONAgent Pro To Download Files

Hi! I’m trying to change a suggested script from this page, http://macscripter.net/viewtopic.php?id=25847.

I have both DEVONAgent Pro and DEVONThink Pro Office.

The URL of the webpage I’m trying to download from is http://www.pro-football-reference.com/years/2014/.

I’m trying to write a script that will download a CSV file from this page but I’m having trouble making it work since the file is not linked as a basic html link but seems to be part of a Javascript table.

For example, the Team Offense tab Javascript looks like this:

Export

I don’t know enough yet about Javascript to be able to write a Do Javascript command that will download the file in the same way should I click the Export option.

Any help would be greatly appreciated!

Hey Don,

It looks to me like you can extract the tables quite easily.


tell application "Safari"
	tell front document to set _text to its text
end tell

–
Chris


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.1 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Download:
example.com/page.html
example.com/file.pdf
– every day
– store to DevonThink database Example and group ExampleGroup.

How?

I was wondering why this question used 2014 stats and then I noticed it’s an old post. But since I’ve also wanted tables from that same page (albeit for more recent seasons)…

The javascript command that would accomplish this is:

document.getElementById('div_team_stats').textContent 

‘div_team_stats’ is the html ID for the ‘team offense’ table on that page.

You should be able perform that command inside a ‘do javascript’.

As the PFR site lazy loads pretty much everything below the fold, you may need to scroll down until that particular table loads.

You can also use the javascript from within the browser console, and thus, do something like this to put the table’s text on the clipboard:

copy(document.getElementById('div_team_stats').textContent)

Try these:

Download page:

tell application "DEVONthink Pro"
	set dul to "https://example.com/page.html"
	
	set this_page to download markup from dul
	
	set cc to create record with {name:"Type", type:html, content:this_page} in parent "ExampleGroup" of database "Example"
	
end tell

Download pdf:

tell application "DEVONthink Pro"
	
	set npd to create PDF document from "http://example.com/file.pdf" in parent "ExampleGroup" of database "Example"
		
end tell

NB I’m using devonthink 2 so it is possible that some of the syntax may have changed.

Offhand, I think devonthink has the built-in ability to do routines automatically.