[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Shoes GUI - downloading site, using reg exs on body

Double Minus

10/16/2008 6:06:00 PM

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....
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
--
Posted via http://www.ruby-....

6 Answers

G.Durga Prasad

10/17/2008 1:52:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

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

On Thu, Oct 16, 2008 at 11:35 PM, Double Minus <nathan.wisman@gmail.com>wrote:

> 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....
> 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
> --
> Posted via http://www.ruby-....
>
>

_why

10/17/2008 3:41:00 PM

0

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/dow...

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

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

jonty

10/17/2008 3:50:00 PM

0

NB: it has an 's'!

<http://shoooes.net/down...



_why wrote:
> 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/dow...
>
> Also, look into the `debug` method, it's great for dumping objects.
> <http://help.shoooes.net/Built-in.html...
>
> 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
>
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - http://w...
> Version: 8.0.173 / Virus Database: 270.8.1/1728 - Release Date: 16/10/2008 07:38
>
>

Double Minus

10/17/2008 11:34:00 PM

0

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.
--
Posted via http://www.ruby-....

Henrik Nyh

10/18/2008 8:23:00 AM

0

On Sat, Oct 18, 2008 at 1:33 AM, Double Minus <nathan.wisman@gmail.com> 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.ne...).

G.Durga Prasad

10/18/2008 9:16:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

On Sat, Oct 18, 2008 at 5:03 AM, Double Minus <nathan.wisman@gmail.com>wrote:

> 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.
> --
> Posted via http://www.ruby-....
>
> 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....
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