If we take a look at this we find the following with our desired information right in the middle. When we run this we get this whole mess of HTML it should look like this: I would add a delay of a second or two to make time for the page to load.
Type2phone applescript examples code#
Next we add the following code to our Applescript under what we already have. To do this, input the following code into the top of your AppleScript: togetInputById (theId ) tell application "Safari"ĭocument.getElementById('" & theId & "').innerHTML " in document 1 Here we are going to use the id=”previous_episode” So… in this case we need to back up and grab the id from the div that contains what we are looking for. There is no name, class, or ID to reference for us to pull. It looks like, again, there is no way to grab the information directly. Next we need to take a look at our desired information… the previous episode. Now, when you run this script it will open the page for Game of Thrones. If tvshow is in link then- checks to see if Game of Thrones is in the outputĮxit repeat- if its found then we stop lookingĮnd if set x to x + 1 - if its not found we continue to the next elementĮnd repeat clicktagName ("a", x ) - clicks the tag that was found to have game of thrones in it Set link to getInputByTag ("a", x ) - this is going to retrieve the input of the element with tag a and the element number x Repeat 1000 times- this is going to repeat with every element number until what we are searching for is found Next place this in your code to search for and click on an element: set x to 0 - this is our test variable Tell application "Safari" -tells AS that we are going to use Safariĭocument.getElementsByTagName('" & theTag & "').innerHTML " in document 1Īlso place this at the top of your doc, it will let you click on an element by tag name: toclicktagName (thetagName, elementnum ) tell application "Safari"ĭo JavaScript "document.getElementsByTagName('" & thetagName & "').click() " in document 1 to getInputByTag ( theTag, num ) - defines a function with two inputs, theTag and num Here is a nifty solution I came up with to find the element and then click on it.įirst place this at the top of your AppleScript doc. It looks like there is no ID, class, or name element… but we can grab it by the “a” attribute tag. Scraping the Textįirst we are going to go to and inspect the element for the first top show Game of Thrones. In this example we are going to be grabbing the previous episode number of a few top television shows and then outputting them to an Excel sheet. If have not read my previous tutorials on clicking, extracting, and inputting data from a web page, this will not make much sense. In this tutorial I am going to show you another real world way to extract information and then output it to an excel document.
Type2phone applescript examples how to#
In previous tutorials we learned how to extract information from a web page.
NEW! AppleScript Maker Beta: Hey Everyone, I am working on a new AppleScript tool that is going to BLOW YOUR MIND! After reading this tutorial use this tool to easily build your AppleScripts.