Forum: Ruby Shoes GUI - downloading site, using reg exs on body

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5e84b05b99dc04797f7821228b9fc4ee?d=identicon&s=25 Double Minus (doubleminus)
on 2008-10-16 20:06
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
F1ae87d23c050dbad815489dbde2f226?d=identicon&s=25 Prasad G. (gdprasad)
on 2008-10-17 15:53
(Received via mailing list)
Did you go through the file
samples/simple-downloader.rb
in the source of the shoes
Prasad
19fdf8bd123216b5056fb856cf1a5771?d=identicon&s=25 _why (Guest)
on 2008-10-17 17:43
(Received via mailing list)
On Fri, Oct 17, 2008 at 03:05:51AM +0900, Double Minus 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
8f433724b1f98215f69bf97dfbfa73d7?d=identicon&s=25 jonty (Guest)
on 2008-10-17 17:51
(Received via mailing list)
NB: it has an 's'!

<http://shoooes.net/downloads/>
5e84b05b99dc04797f7821228b9fc4ee?d=identicon&s=25 Double Minus (doubleminus)
on 2008-10-18 01:34
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.
4a551074ddba4460f95d011c47190d0e?d=identicon&s=25 Henrik --- (malesca)
on 2008-10-18 10:24
(Received via mailing list)
On Sat, Oct 18, 2008 at 1:33 AM, Double Minus 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/).
F1ae87d23c050dbad815489dbde2f226?d=identicon&s=25 Prasad G. (gdprasad)
on 2008-10-18 11:16
(Received via mailing list)
On Sat, Oct 18, 2008 at 5:03 AM, Double Minus 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
This topic is locked and can not be replied to.