Load cookie

Hi all. I’ve searched the forums and haven’t found anything I can get to work.

I have a need to login to a secure site, refresh frequently, search for a link with certain text, and follow it if it is there.

Automator seems to be able to handle most of this, but I’m having trouble loading my cookie so that automator has access to the secure information. Is there a way to load a cookie with applescript so that automator can scrape for links?


Wow, I can’t believe nobody knows how to do this. I think I would probably pay for the answer at this point. Google is no help. And yes, most links you could give me I’ve probably already checked.


take a look at this: http://forums.macosxhints.com/showthread.php?t=60241

Hope it helps

Yeah, I thought that was my holy grail too, but I can’t seem to make it work for me. I was hoping for some guidance. Thanks for posting something, at least.

I have not looked at or worked on that script for cookies for a while, and I can already feel the grey matter starting to ache… :wink:
What part are you getting stuck on.

Hey thanks for replying. This post feels like a ghost town.

I’m not fluent with any scripting or programming language, so most of the time I have difficulty sorting through the things I don’t need to get to the things I DO need, as in some of the other cookie examples posted.

I just need Applescript to access a secure page using my stored cookie file (Safari or Firefox), so I can scrape for links. There seems to be a couple ways to do it, neither of which I am familiar with.

Do you think you might be able to get me started?

do you need to login? you could use javascript code within your applescript code to push your user/pw and login you in and then continue to nav to the page with links.

code would look something like this (you will need to modify the form variables to the ones on your site):

set USER_NAME to "enter your user name here"
set USER_PASSWORD to "enter your password here"

tell application "Safari" to do JavaScript ("document.forms['frmData'].elements['strUsername'].value = '" & USER_NAME & "';document.forms['frmData'].elements['strPassword'].value = '" & USER_PASSWORD & "';") in document 1
tell application "Safari" to do JavaScript ("document.forms['frmData'].submit();") in document 1

I don’t need it to login. I can do that with Safari. Trouble is, if I try to scrape for links, even with automator, the site KNOWS that I’m not doing things the right way, and give me a “your session has ended” page. So I just need to use the cookie that Safari has stored, and spoof the Safari session with Applescript.

how are you SCRAPEing?

you could use this code to get content and the scrub through it in Applescript using text item delimiters or other methods to get your links.

tell application "Safari"
	set documentSource to source of document 1
	set documentText to text of document 1
end tell

Yeah, that sounds like a good way. I thought about that, but I don’t know how to do it. Also, it needs to be able to open one of those links if it finds the right one, and then submit a form.

I’ll play around with the code you suggested and see what I can learn. In the meantime, any thoughts, details?

Wow guys, turns out Javascript handles everything I need to do just fine.

Thanks to CarbonQuark for the idea to use the html source code from the page. I did a little research with that in mind, and I’ve ended up with this:

tell application "Safari"
	set myJavaScript to "

function ScrapeFor(theURLSubstring){
	var foundLinks = new Array();
	var thisIndex = 0;
	// For every link
	var linkCount =  document.links.length;
	for (i=0; i < linkCount; i++){
		var thisLink = document.links[i];
		var linkOffset = thisLink.href.indexOf(theURLSubstring);
		if (linkOffset != -1){
			window.location = thisLink;		

	set myLinks to do JavaScript myJavaScript in document 1
end tell

If you test it on Google’s homepage, it’ll find the privacy link and follow it. Turns out you don’t need to mess with cookies at all if you’re on a secure page.

Now all I need is to find a form and have javascript post it. Should be smooth sailing from here.

Alright, I 'spose I’m stuck again. I’M SOOOO close!

So I’ve got it to find and open the link I need. Then it needs to automatically submit a form on the new page, but for some reason it’s not working. This is what I have:

window.open (thisLink);

I figured this would open the link in a new window, and then submit the first form in that new window. What it does INSTEAD is open a new window, then submit the first form in the PARENT window.

What’s happening? How do I fix that?


Plus, check out my band: http://www.librosenfuego.com

Need to see more of you script to offer a good suggestion.

You could try this:

tell application "Safari"
	tell document frontmost
	 -- your code here
	end tell
end tell


Another thought…

You could try the Firefox plugin called “iMacros for Firefox”


Yeah I’ve seen that. I installed it a while ago and it looked more confusing than what I’m doing now. Plus I’m not very familiar with Firefox. Thanks though.