# Shoes GUI - downloading site, using reg exs on body

**URL:** <https://www.ruby-forum.com/t/shoes-gui-downloading-site-using-reg-exs-on-body/151100>\
**Category:** Ruby\
**Created:** [October 16, 2008, 8:06pm UTC](https://www.ruby-forum.com/t/shoes-gui-downloading-site-using-reg-exs-on-body/151100 "2008-10-16T20:06:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![doubleminus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5daacb/32.png) [@doubleminus](https://www.ruby-forum.com/u/doubleminus)\
**Post date:** [October 16, 2008, 8:06pm UTC](https://www.ruby-forum.com/t/shoes-gui-downloading-site-using-reg-exs-on-body/151100/1 "2008-10-16T20:06:18Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![doubleminus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5daacb/32.png) [@doubleminus](https://www.ruby-forum.com/u/doubleminus)\
**Post date:** [October 17, 2008, 3:53pm UTC](https://www.ruby-forum.com/t/shoes-gui-downloading-site-using-reg-exs-on-body/151100/2 "2008-10-17T15:53:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![doubleminus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5daacb/32.png) [@doubleminus](https://www.ruby-forum.com/u/doubleminus)\
**Post date:** [October 17, 2008, 5:43pm UTC](https://www.ruby-forum.com/t/shoes-gui-downloading-site-using-reg-exs-on-body/151100/3 "2008-10-17T17:43:31Z")

</div>

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/](http://shoooes.net/download/)

Also, look into the `debug` method, it’s great for dumping objects.  
[http://help.shoooes.net/Built-in.html#debug](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

---

<div class="post-metadata">

**Author:** ![doubleminus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5daacb/32.png) [@doubleminus](https://www.ruby-forum.com/u/doubleminus)\
**Post date:** [October 18, 2008, 1:34am UTC](https://www.ruby-forum.com/t/shoes-gui-downloading-site-using-reg-exs-on-body/151100/4 "2008-10-18T01:34:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![doubleminus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5daacb/32.png) [@doubleminus](https://www.ruby-forum.com/u/doubleminus)\
**Post date:** [October 17, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/shoes-gui-downloading-site-using-reg-exs-on-body/151100/5 "2008-10-17T17:51:08Z")

</div>

NB: it has an ‘s’!

[http://shoooes.net/downloads/](http://shoooes.net/downloads/)

---

<div class="post-metadata">

**Author:** ![doubleminus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5daacb/32.png) [@doubleminus](https://www.ruby-forum.com/u/doubleminus)\
**Post date:** [October 18, 2008, 10:24am UTC](https://www.ruby-forum.com/t/shoes-gui-downloading-site-using-reg-exs-on-body/151100/6 "2008-10-18T10:24:38Z")

</div>

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/](http://code.whytheluckystiff.net/hpricot/)).

---

<div class="post-metadata">

**Author:** ![doubleminus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5daacb/32.png) [@doubleminus](https://www.ruby-forum.com/u/doubleminus)\
**Post date:** [October 18, 2008, 11:16am UTC](https://www.ruby-forum.com/t/shoes-gui-downloading-site-using-reg-exs-on-body/151100/7 "2008-10-18T11:16:42Z")

</div>

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/](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/](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
