• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: curl equivalence
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: curl equivalence


  • Subject: Re: curl equivalence
  • From: kai <email@hidden>
  • Date: Wed, 26 Oct 2005 00:48:25 +0100


On 25 Oct 2005, at 20:55, John R. wrote:

[snip: curl stuff]

Therefore, Applescript is ideal for automating Safari to do it right. However, the problem is knowing when the HTML is ready for capture, without waiting forever++

I offer you guys the following code, which works MOST of the time (eg. a frames problem that Gary clarified on another posting.)

Questions:
     Why should it have to be this damn complicated?
     Any ideas for doing it better?

Doesn't this do about the same thing, John?

----------

to getHTML from myURL
    tell application "Safari" to tell document 1
        set URL to myURL
        repeat 40 times
            if URL is myURL then return source
            delay 0.5
        end repeat
    end tell
    error "Oops - problem accessing internet..."
end GetHTML

getHTML from "http://www.apple.com/";

----------

---------------------------------------------------------------------- ----------
on run
GetHTMLfromWebsite("http://www.apple.com";)
end run
---------------------------------------------------------------------- ----------
on GetHTMLfromWebsite(myURL)
tell application "Safari"
set URL of document 1 to myURL
if my WindowLoadProblem(id of window 1) then error "Oops - problem accessing internet..."
return source of document 1
end tell
end GetHTMLfromWebsite
---------------------------------------------------------------------- ----------
on WindowLoadProblem(winID)
--------------------------------------------
-- Step #1: Window name change signals the start of a load.
-- Note: WINDOW name is testable, but DOCUMENT name is not!
--------------------------------------------
tell application "Safari"
set the name of window id winID to "Waiting to Start!!!"
set thisName to "Untitled"
repeat until thisName does not contain "Waiting to Start!!!"
delay 0.5
set thisName to name of window id winID
end repeat
end tell
--------------------------------------------
-- Step #2: Javascript "readyState" signals the completion
-- Problem: apparently, use of HTML frames may set readyState prematurely!
--------------------------------------------
set pagefailed to true
set n to 0
repeat until (not pagefailed) or (n = 40)
delay 0.5 -- seconds delay between tries, with a timeout after 40 tries
set n to n + 1
tell application "Safari" to set r to ¬
(do JavaScript "document.readyState" in document 1 of window id winID)
if r = "complete" then
set pagefailed to false
end if
end repeat
return pagefailed
end WindowLoadProblem
---------------------------------------------------------------------- ----------

--- kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: curl equivalence
      • From: kai <email@hidden>
References: 
 >curl equivalence (From: "John R." <email@hidden>)

  • Prev by Date: Re: Producing Unicode-only characters [was: Finding \t, \r, \n reliably]
  • Next by Date: Re: curl equivalence
  • Previous by thread: curl equivalence
  • Next by thread: Re: curl equivalence
  • Index(es):
    • Date
    • Thread