Shoes GUI - downloading site, using reg exs on body

So I want my app to download the text of a site’s body (easy) and then I
want to use regular expressions to pick out chunks of text.

In my very limited skills/knowledge, I’ve had a hard time getting this
working. I’ve tried two approaches…

Code:

Shoes.app do

stack :left => 65, :top => 75 do
@results = para “results”
end

stack (:left => 165, :top => 180) do
para “URL:”
flow do
button “Clear” do
@status.replace “results cleared…” and
@searching.replace " " and
@results.replace “results”
end
@url = edit_line “http://www.google.com/
button “OK” do

stack do
     @searching = title "Searching site", :size => 16
      @status = para "One moment..."
        download @url.text do |site|
          @status.text = "Body: " + site.response.body.inspect
          regex = Regexp.new(/http/)
          matchdata = @status.text
            if matchdata
                @results.text = matchdata[1]
            else
                @results.text = "NO MATCH"
            end
          end
      end
    end
  end
end

end

That doesn’t work.

This is the other approach:
@status.text = "Body: " + site.response.body.inspect
if @status.text =~ /html/ then
@results.text = $1

Any advice/guidance? Am I even on the right track?

double

Did you go through the file
samples/simple-downloader.rb
in the source of the shoes
Prasad

On Fri, Oct 17, 2008 at 03:05:51AM +0900, Double M. wrote:

Any advice/guidance? Am I even on the right track?

Your script works. Have you tried the latest 0.r1057 release?
http://shoooes.net/download/

Also, look into the debug method, it’s great for dumping objects.
http://help.shoooes.net/Built-in.html#debug

If your script really isn’t working for you on the latest Shoes,
send me an email with your platform and any errors in the console.

_why

It is working - I guess I just don’t understand how…

It prints some numbers into the @results para. I want to find and pull
links out of the body text. I was starting with a very basic search, to
just try to have it pull out every line with “http” in it.

(/^*http/$/) doesn’t work for my reg ex

I get:

rb:23: invalid regular expression; there’s no previous pattern, to which
‘*’ would define cardinality at 2: /^*http/$/

double

And why: thank you for this amazing, fun learning tool. It has been
invaluable in figuring out what Ruby is all about.

NB: it has an ‘s’!

http://shoooes.net/downloads/

On Sat, Oct 18, 2008 at 1:33 AM, Double M. wrote:

I was starting with a very basic search, to
just try to have it pull out every line with “http” in it.

(/^*http/$/) doesn’t work for my reg ex

I get:

rb:23: invalid regular expression; there’s no previous pattern, to which
‘*’ would define cardinality at 2: /^*http/$/

See if you can find a good guide to regular expressions – they’re
very useful once you learn them. Your regexp is invalid because “" in
regexps does not mean “any characters, or no characters”, it means
“any, or none, of the preceding character or group”. So ".
” (any or
none of any character) is probably what you intended.

You forgot the “:” between “http” and “/” though, if you intended to
match “http:/”.

If you’re doing real simple HTML munching, regexps can be fine, but
look into Hpricot (http://code.whytheluckystiff.net/hpricot/).

On Sat, Oct 18, 2008 at 5:03 AM, Double M. wrote:

rb:23: invalid regular expression; there’s no previous pattern, to which
‘*’ would define cardinality at 2: /^*http/$/

double

And why: thank you for this amazing, fun learning tool. It has been
invaluable in figuring out what Ruby is all about.

Posted via http://www.ruby-forum.com/.

I took this as an exercise and here is what I came up with:
Shoes.app do

stack :left => 65, :top => 75 do
@results = para “results”
end

stack :left => 165, :top => 180 do
para “URL:”
flow do
button “Clear” do
@status.replace “results cleared…” and
@searching.replace " " and
@results.replace “results”
end
@url = edit_line “http://www.google.com/
button “OK” do

stack do
@searching = title “Searching site”, :size => 16
@status = para “One moment…”
download @url.text do |site|
@searching.replace “Results”
@results.replace “”
content = site.response.body.inspect
array = content.split(/"/).map{|e| e.chop }
@status.text = array.grep(/^http/).join(“\n”)
end
end
end
end
end
end