I’m relatively new to AppleScript so please bear with me.
In a nutshell, I’d like to make an AppleScript that takes a list of words from a text file (separated by line breaks) and finds their popularity on Google.
This shouldn’t be too hard, especially because in every google search result, the same consistent string of text ("Results 1 - 10 of about ") comes right before the number that’s important. But I don’t know how to manipulate text very well…hopefully that’s where you come in.
What would be ideal is if this script could append the Google result right at the end of each word in the text file, in essence turning this:
set theBrowser to “Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)”
set theStartTag to “ of about ”
set theEndTag to “ for ”
set theSearchTerm to text returned of (display dialog ¬
“What search words to use? (use + as word spacer)” default answer ¬
“” buttons [" OK "] default button 1)
set tempArray to arrayFromText(theCode, theStartTag)
set theFirstPart to item 2 of tempArray
set tempArray to arrayFromText(theFirstPart, theEndTag)
set theNumberString to item 1 of tempArray
display dialog theNumberString
on arrayFromText(theString, myText)
set myDelimiters to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {myText}
set myList to (text items of theString) as list
set AppleScript’s text item delimiters to myDelimiters
return myList
end arrayFromText
John, many many thanks for the great code - I couldn’t have asked for anything more perfect. And thanks for bringing this to my attention hhas. I’ll see if I can get permission from Google to continue - I’m trying to see whether or not sequences of the Golden Ratio are more popular on Google than a series of random numbers. It could be a fun project but I don’t want to get into legal trouble because of my itch to study armchair mathematics.
You might want to look into the Google API http://www.google.co.uk/apis/ if you are intending to do a large ammount of querying Google.
If you get a key for their API (It’s free - they just want your email address) I have some Applescript code somewhere that you could use to get your results. The results you get for the estimated pages in their API does vary from their web interface however (I don’t understand why).