PDA

View Full Version : Applescript works sometimes




grashapa1
Jun 23, 2008, 05:43 PM
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
Jun 23, 2008, 08:11 PM
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
Jun 23, 2008, 09:03 PM
Add "delay 1" in-between "open location bla bla" and "set pSource to the source of the front document"

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

grashapa1
Jun 23, 2008, 09:54 PM
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
Jun 23, 2008, 11:35 PM
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?
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
Jun 24, 2008, 01:12 AM
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?