Scraping Stack Overflow is especially easy with Shoes and Hpricot.
require 'hpricot'
Shoes.app :title => "Ask Stack Overflow", :width => 370 do
SO_URL = "http://stackoverflow.com"
stack do
stack do
caption "What is your question?"
flow do
@lookup = edit_line "stackoverflow", :width => "-115px"
button "Ask", :width => "90px" do
download SO_URL + "/search?s=" + @lookup.text do |s|
doc = Hpricot(s.response.body)
@rez.clear()
(doc/:a).each do |l|
href = l["href"]
if href.to_s =~ /\/questions\/[0-9]+/ then
@rez.append do
para(link(l.inner_text) { visit(SO_URL + href) })
end
end
end
@rez.show()
end
end
end
end
stack :margin => 25 do
background white, :radius => 20
@rez = stack do
end
end
@rez.hide()
end
end