Re: I need to allow a web page to fully load before saving it with my script
Re: I need to allow a web page to fully load before saving it with my script
- Subject: Re: I need to allow a web page to fully load before saving it with my script
- From: Laine Lee <email@hidden>
- Date: Fri, 05 Nov 2010 16:42:42 -0500
- Thread-topic: I need to allow a web page to fully load before saving it with my script
Title: Re: I need to allow a web page to fully load before saving it with my script
On 9/15/10 9:04 AM, "email@hidden" <email@hidden> wrote:
>
> On Sep 14, 2010, at 11:16pm, Jeff Porrello wrote:
>
>> I need to allow a web page to fully load before saving it with my script.
>>
>
> Here's a solution from the archives that I've used. If you are downloading a
> PDF you can use the trick where you check the size of the pdf every few
> seconds, knowing that if the size hasn't changed in the last 10 seconds it's
> downloaded.
>
> HTH
>
> ES
>
>> On Aug 2, 2009, at 6:01am, Adam Morris wrote:
>>
>>> Hi all,
>>>
>>> I have a program that downloads the PDFs provided from a webpage from my
>>> university (for copying automatically to my Kindle). I've been using the
>>> delay command to make it wait for the download and has worked fine, but I've
>>> always wanted a script function that would loop until Safari's front page
>>> stopped loading. This is what I have been using:
>>>
>>> on waitforload()
>>> tell application "Safari"
>>> delay 1
>>> repeat
>>> set thisDoc to front document
>>> if (do _javascript_ "document.readyState" in thisDoc) is "complete" then exit
>>> repeat
>>> delay 2 -- wait a second before checking again
>>> end repeat
>>> delay 1
>>> end tell
>>> end waitforload
>>>
>>> This only works for the loading of the HTML/CSS/DOM side, but doesn't
>>> reflect the fact that, in some cases (including mine) the
>>> document.readyState shows "complete" even though the document itself
>>> actually downloading a PDF.
>
>
If you want one that doesn't use _javascript_, try this UI scripting method. (I take the test sometimes and it's harder than it used to be. How about you?)
tell application "Safari"
make new document at end of documents
set URL of document 1 to "http://www.sagetest.osu.edu/SageScoringInstructions-42308.pdf"
activate
end tell
repeat
delay 1
tell application "System Events"
tell process "Safari"
click grow area 1 of window 1
set s to (enabled of (menu item "Stop" of menu 1 of menu bar item "View" of menu bar 1))
if s is false then
exit repeat
end if
end tell
end tell
end repeat
activate
display dialog "Loading complete."
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden