Re: advanced safari work....
Re: advanced safari work....
- Subject: Re: advanced safari work....
- From: Roger Howard <email@hidden>
- Date: Wed, 28 Jul 2004 13:49:00 -0700
On Jul 28, 2004, at 1:05 PM, Erik Ness wrote:
>
Greetings,
>
>
I want to develop a script that will allow me to scan a web page for
>
certain links, then make a variety of different choices based on what
>
links are there.
>
>
This is a significant leap up the scripting ladder for me, and I'd
>
appreciate a leg up. My plan was to capture the source and search that
>
for various strings. Any better ideas or scripts or snippets thereof
>
that people might be willing to share?
Get to know JavaScript/DOM a bit - for instance this little bit of code:
tell application "Safari" to do JavaScript "document.links[1].host" in
first document
Gets the hostname of the second link (JavaScript arrays are
zero-indexed) in the first (frontmost) document in Safari.
Using JavaScript is FAR easier than trying to write a robust HTML
parser for AppleScript, and you've got the benefit of the entire DOM
interface at your disposal.
Avoid trying to do this without using Do JavaScript... it's far easier
to use DOM to interact with a Web page essentially as a structured
object.
Of course if you want to do it WITHOUT using Safari or other scriptable
browser then you're back to parsing source... but beware!
- R
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.