! Copyright (C) 2006 Chris Double. All Rights Reserved. ! See http://factorcode.org/license.txt for BSD license. ! USING: kernel http-client namespaces io errors sequences rss ; IN: google-search : build-soap-request ( key string -- soap ) #! Return the soap request for a google search [ "" % "" % "" % "" % " " % swap % "" % " " % % "" % " 0" % " 10" % " true" % " " % " false" % " " % " latin1" % " latin1" % "" % " " % " " % ] "" make ; TUPLE: search-item url snippet title ; : parse-result ( string -- seq ) "resultElements" swap between-tags "item" swap child-tags [ [ "URL" swap between-tags ] keep [ "snippet" swap between-tags ] keep "title" swap between-tags ] map ; : google-search ( key string -- result ) #! Perform a google searching using the Google Web API #! key and the search string. build-soap-request "text/xml" swap "http://api.google.com/search/beta2" http-post rot 200 = not [ 2drop "Google search failed." throw ] [ nip ] if parse-result ;