• 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: Getting a link from a safari window
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting a link from a safari window


  • Subject: Re: Getting a link from a safari window
  • From: Axel Luttgens <email@hidden>
  • Date: Sun, 23 May 2010 10:38:35 +0200

Le 22 mai 2010 à 23:03:59, email@hidden a écrit :

> Hi,
>
> Using UI Scripting (with a lot of help from UI Browser) I've been able to identify specific links on a Safari page and click the links to open the linked page.
>
> It would really help my script if I could get the link's URL first. This script will be visiting hundreds of pages, but if I can't determine if it's visited the URL already, it would be 1000s of pages.
>
> I've looked at the source and the URLs are generated by Java script or something, so their text does not actually appear in the source.

Hello Ed,

Assuming you're ultimately interested in the URLs only, perhaps could you avoid UI scripting entirely with some bits of JavaScript. Here follows a very rough example:

	on CountLinks()
		tell document 1 of application "Safari" to do JavaScript "document.links.length"
	end CountLinks

	on GetLinkHref(L)
		tell document 1 of application "Safari" to do JavaScript "document.links[" & L & "].href"
	end GetLinkHref

	repeat with I from 1 to CountLinks()
		set thisHref to GetLinkHref(I)
		-- do something wit thisHref
	end repeat

Of course, depending of your needs, this may be either plain irrelevant or subject to many variants/optimizations.

HTH,
Axel

 _______________________________________________
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

  • Follow-Ups:
    • Re: Getting a link from a safari window
      • From: Axel Luttgens <email@hidden>
References: 
 >Getting a link from a safari window (From: "email@hidden" <email@hidden>)

  • Prev by Date: AppleScript and Valentina Database
  • Next by Date: Re: UI Scripting
  • Previous by thread: Re: Getting a link from a safari window
  • Next by thread: Re: Getting a link from a safari window
  • Index(es):
    • Date
    • Thread