Script 2

Presentation Notes

How do we find the base URL needed to run the search?

For GET requests, it is easy. Run a search and look at the URL of the results page. In our case, the URL is http://search.yahoo.com/bin/search?p=applescript+user+group

So, since all we typed in was applescript user group, it seems clear the base URL is http://search.yahoo.com/bin/search?p=

Now, we add the ability to type in the search terms in a dialog box. (applescript user group). Notice the result? A 400 error. Why? [Look at results page URL again]

Ah, we forgot to notice that the search terms need to be separated by the Ôplus sign' in order to be interpreted correctly. Spaces are not valid in URLs - some sites turn them into the their ASCII representation %20, while some just use the Ôplus sign' to separate search terms. That's what we need here.

Script Source

property searchBase : "http://search.yahoo.com/bin/search?p="

property searchTerms : ""

set searchTerms to text returned of Â

(display dialog "Enter your search terms:" default answer "")

set searchURL to searchBase & searchTerms

-- get the source as a string

set sourceHTML to (do shell script "curl " & quoted form of searchURL & " | vis")

sourceHTML