Time for action – making a links extraction function
Sometimes it's handy to create tests in a separate stack, and then to copy the function you've made into your application stack.
Create a new Mainstack. Save it, just to be safe!
Add a couple of fields and a button.
Set the button's script to this:
on mouseUp put url "http://www.runrev.com/" into field 1 put getLinks(field 1) into field 2 end mouseUp
Edit the stack script, and create a function for
getLinks
. Start with it just returning what it's sent:function getLinks pPageSource return pPageSource end getLinks
If you were to try clicking on the button at this point, you will see that the whole page source appears in field 2.
We're going to use the filter function, and that needs the text to be in separate lines. So we want each link to be in a line of its own. The replace function can do that nicely. Add these two lines to the script (before the
return
line, of course!):replace "/a>" with "/a>" & return in pPageSource...