Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

grashapa1

macrumors newbie
Original poster
Jun 23, 2008
4
0
I have written an applescript program that seems only to work on certain websites. I am trying to take the pageSource of website and transfer it to excel.

tell application "Safari"
open location "http://www.microsoft.com/mac/developers/default.mspx?CTT=PageView&clr=99-21-0&target=b2656752-dbbb-494e-ad09-031d08e7bc8e1033&srcid=cdb9a274-738f-4e4a-9e8c-83feda0485241033&ep=7"
set pSource to the source of the front document
end tell
tell application "Finder"
activate
open document file "Sorting Info.xls" of folder "Research Data" of folder "Desktop" of folder "Rich" of folder "Users" of startup disk
end tell
tell application "Microsoft Excel"
activate
activate object workbook "Sorting Info.xls"
activate object worksheet "Sheet1"
set theRange to range "A1:A100" of sheet 1 of active workbook
set value of active cell to pSource
end tell

However, if i usedhttp://www.google.com or http://finance.google.com/finance?q=ABC the data doesn't seem to transfer

Can anyone help me figure out what is going wrong?

Also, I would appreciate it if someone could help me figure out how to make one line of the page Source appear as one cell in Excel
 

grashapa1

macrumors newbie
Original poster
Jun 23, 2008
4
0
After playing with this more, I have learned that if you just type

tell application "Safari"
open location "http://finance.google.com/finance?q=ABC"
set pSource to the source of document 1
end tell


you can make the pagesource appear in the results
However, if you add the display dialogue


tell application "Safari"
open location "http://finance.google.com/finance?q=ABC"
set pSource to the source of document 1
display dialogue pSource
end tell

you get a blank box that pops out
 

lancestraz

macrumors 6502a
Nov 27, 2005
898
0
RI
Add "delay 1" in-between "open location bla bla" and "set pSource to the source of the front document"

Code:
open location "http://www.google.com"
delay 1
set pSource to the source of the front document
 

grashapa1

macrumors newbie
Original poster
Jun 23, 2008
4
0
That doesn't solve the problem. I had tried that previously. It doesn't depend on the delay. Somehow the data doesn't seem to be transferring.
 

lancestraz

macrumors 6502a
Nov 27, 2005
898
0
RI
That doesn't solve the problem. I had tried that previously. It doesn't depend on the delay. Somehow the data doesn't seem to be transferring.
Typical AppleScript weirdness... It works fine for me.

Does this work?
Code:
tell application "Safari"
	open location "http://finance.google.com/finance?q=ABC"
	set pSource to the source of document 1
end tell

tell application "TextEdit"
	activate
        make new document
	set text of the front document to pSource
end tell
 

grashapa1

macrumors newbie
Original poster
Jun 23, 2008
4
0
safari page source to excel

That works fine, but I specifically need the pagesource to transfer to excel. I have a bunch of formulas in excel that sort the urls for me. However, the point of this applescript is to allow me to sort through hundreds of companies. Does anyone recommend anything besides applescript? or how should I do this?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.