Yahoo! search interface: Difference between revisions

Content added Content deleted
m (→‎{{header|C sharp}}: Add argument to {{lines too long}}.)
(icon)
Line 126: Line 126:
<lang guiss>Start,Programs,Applications,Mozilla Firefox,Inputbox:address bar>www.yahoo.co.uk,
<lang guiss>Start,Programs,Applications,Mozilla Firefox,Inputbox:address bar>www.yahoo.co.uk,
Button:Go,Area:browser window,Inputbox:searchbox>elephants,Button:Search</lang>
Button:Go,Area:browser window,Inputbox:searchbox>elephants,Button:Search</lang>

==Icon and {{header|Unicon}}==
The following uses the Unicon pre-processor and messaging extensions and won't run under Icon without significant modification.
<lang Icon>link printf,strings

procedure main()
YS := YahooSearch("rosettacode")
every 1 to 2 do { ######
YS.readnext()
YS.showinfo()
}
end

class YahooSearch(urlpat,page,response) #: class for Yahoo Search
method readnext() #: read the next page of search results
self.page +:= 1 # can't find as w|w/o self
readurl()
end
method readurl() #: read the url
url := sprintf(self.urlpat,(self.page-1)*10+1)
m := open(url,"m") | stop("Unable to open : ",url)
every (self.response := "") ||:= |read(m)
close(m)
self.response := deletec(self.response,"\x00") # kill stray NULs
end

method showinfo() #: show the info of interest
self.response ? repeat {
(tab(find("<")) & ="<a class=\"yschttl spt\" href=\"") | break
url := tab(find("\"")) & tab(find(">")+1)
title := tab(find("<")) & ="</a></h3></div>"
tab(find("<")) & =("<div class=\"abstr\">" | "<div class=\"sm-abs\">")
abstr := tab(find("<")) & ="</div>"
printf("\nTitle : %i\n",title)
printf("URL : %i\n",url)
printf("Abstr : %i\n",abstr)
}
end
initially(searchtext)
urlpat := sprintf("http://search.yahoo.com/search?p=%s&b=%%d",searchtext)
page := 0
end</lang>

{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/printf.icn printf.icn provides formatting]
[http://www.cs.arizona.edu/icon/library/src/procs/strings.icn strings.icn provides deletec]

Output:<pre></pre>


=={{header|Java}}==
=={{header|Java}}==