• 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: HTML parsing--need to be able to click on parsed elements
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: HTML parsing--need to be able to click on parsed elements


  • Subject: Re: HTML parsing--need to be able to click on parsed elements
  • From: Axel Luttgens <email@hidden>
  • Date: Fri, 10 Jun 2016 12:19:00 +0200

> Le 10 juin 2016 à 05:39, William Dockery a écrit :
>
> […]
>
> However, what I failed to clarify to you and to myself is that I need more than text, or dates.  I actually want to CLICK on the first element that matches:
>
> <A href="#"onclick=“refreshSession
>
> This text pattern signifies an HTML element that, when clicked, will download a specific type of document, which is my general objective.  Clicking on the first of these elements will download the most recent document, which is my specific objective.
>
> And I can’t just search for <A and click on the first <A element, because there are several other irrelevant <A elements higher up in the source of the page.
>
> […]

Hello William,

Since Safari provides the "do javascript" command, you may try to delegate as much as possible to JavaScript.

For example, assuming that
- the above conditions are sufficient
- the ordering of the DOM elements reflects the ordering of the links as viewed in the browser window
you could try:

set js_code to "

// Let's fetch the document's anchors.
var a = document.getElementsByTagName('a');

// Loop over the anchors.
for (var i = 0; i < a.length; i++)
{
	// Skip anchors whose href is not '#'.
	if ( a[i].href != '#' ) {
		continue;
	}
	// Skip anchors not having a 'onclick' attribute.
	if ( a[i].onclick == null ) {
		continue;
	}
	// Skip anchors whose 'onclick' attribute does not contain the
	// exepected call of 'refreshSessionAndPopupWindow'
	if ( a[i].onclick.toString().indexOf('refreshSessionAndPopupWindow(') < 0 ) {
		continue;
	}

	// We found a suitable anchor; let's click it.
	a[i].click();

	// We're done: we are interested in the first suitable anchor only.
	break;
}
"

tell application "Safari"
	tell front window
		tell current tab
			do JavaScript js_code
		end tell
	end tell
end tell

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


References: 
 >Re: HTML parsing (From: William Dockery <email@hidden>)
 >Re: HTML parsing (From: "Stockly, Ed" <email@hidden>)
 >Re: HTML parsing (From: Deivy Petrescu <email@hidden>)
 >Re: HTML parsing--need to be able to click on parsed elements (From: William Dockery <email@hidden>)

  • Prev by Date: Re: Best Method to Filter Lists?
  • Next by Date: Re: Getting Individual Metadata Items with ASObjC
  • Previous by thread: Re: HTML parsing--need to be able to click on parsed elements
  • Next by thread: Re: HTML parsing--need to be able to click on parsed elements
  • Index(es):
    • Date
    • Thread