« Back to Blog

Recursive Google suggestions

| No Comments | Published on December 1, 2012
The content that follows was originally published on the Don Havey website at http://donhavey.com/blog/uncategorized/recursive-google-suggestions/

Beginning from a initial string, take the last word of each Google complete suggestion and start a new suggestion with it:

how do i put this gently synonyms for amazing racebuddy freeport maine state lottery numbers in spanish translation spanish to english to spanish translator french to english to spanish translation english to italian restaurants portland maine state lottery nhl lockout trailer park boys names for girls go gamestop hours

how do you take a screenshot on a macys furniture stores in maine state lottery nhl lockout supplements for anxiety attack of the showtime schedule starbucks menusinla

why do cats purrloin evolutionary psychology today showtime schedule starbucks menusinla

am i registered to voter registration maine state lottery nhl lockout supplements for anxiety attack of the showtime schedule starbucks menusinla

how far along am iphone 538 senate races in maine state lottery numbers in spanish translation english to italian restaurants portland maine state lottery numbers in spanish translation spanish to english to spanish translation english to italian restaurants portland maine state lottery numbers in spanish translator french to english to spanish translation english to italian restaurants portland maine state lottery nhl lockout supplements for anxiety attack of the showtime schedule starbucks menusinla

All roads lead to “menusinla” from my location outside of Portland, Maine, apparently. Code:


boolean get_text(String $s){
  XML xml = loadXML("http://google.com/complete/search?output=toolbar&q="+$s);
  if(xml==null) return false;
  XML[] suggestions = xml.getChildren("CompleteSuggestion");
  if(suggestions==null) return false;
  for(int i=0;i<suggestions.length;i++){
    XML[] suggestion = suggestions[i].getChildren("suggestion");
    if(suggestion[0]==null||!suggestion[0].hasAttribute("data")) return false;
    if(suggestion[0].getString("data").equals($s)) continue;
    s = s.substring(0,s.lastIndexOf(" ")+1)+suggestion[0].getString("data");
    break;
  }
  return true;
}


String s = "";
get_text("how%20far");
while(n<50&&get_text(s.substring(s.lastIndexOf(" ")+1))) n++;
println(s);

Or for slightly more interesting results, take the last two words of the suggested query, rather than just the last one, then remove those two words and append the suggestion.

how do you take a screenshot on a machine for pigs the bell tolls

how do i put this guitar gently weeps

i wish i waste so much time will where will blagojevich serve time


boolean suggest(){
  String[] $s = s.split(" ");
  XML xml = loadXML("http://google.com/complete/search?output=toolbar&q="+$s[max(0,$s.length-2)]+"%20"+$s[max(0,$s.length-1)]);
  s = "";
  for(int i=$s.length-3;i>=0;i--) s = $s[i]+" "+s;
  s = trim(s);
  if(xml==null) return false;
  XML[] suggestions = xml.getChildren("CompleteSuggestion");
  if(suggestions==null) return false;
  for(int i=0;i<suggestions.length;i++){
    XML[] suggestion = suggestions[i].getChildren("suggestion");
    if(suggestion[0]==null||!suggestion[0].hasAttribute("data")) return false;
    $s = suggestion[0].getString("data").split(" ");
    if($s.length<2) continue;
    s += " "+suggestion[0].getString("data");
    return true;
  }
  return false;
}


String s = "i wish i was";
int n = 0;
while(n<50&&suggest()) n++;
println(s);

Categories: Blog / Uncategorized

Leave a Response

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>