Seeking for a ruby spider robot example

H

Haofei

Hi, i want to write a little spider to do some web search
but have no idea how to start it. is there any example or something like that?
thanks :)












yuesefa
 
J

Justin Collins

Haofei said:
Hi, i want to write a little spider to do some web search
but have no idea how to start it. is there any example or something
like that?
thanks :)

yuesefa

You can see an extremely simple/limited one that I made a while back:

http://students.seattleu.edu/collinsj/programs_netcrawler.html

It may give you a place to start, but there are very good libraries for
getting and parsing websites, like Rubyful Soup, Mechanize, open-uri,
and so on.

Also, try searching the archives for more.

-Justin
 
A

Aaron Patterson

Hi, i want to write a little spider to do some web search
but have no idea how to start it. is there any example or something like
that?
thanks :)

yuesefa

You can write one with WWW::Mechanize. I have an example on my blog:

http://tenderlovemaking.com/2006/05/26/mechanize-one-liners/

There is also an example spider that comes along with Mechanize, just
look in the 'eg' directory.

Here is the spider for those that don't want to click (its not perfect,
but its small!):

(mech = WWW::Mechanize.new).get(ARGV[0])
(a = lambda { |p|
mech.page.links.each { |l|
mech.click(l) && p.call(p) if ! mech.visited? l
}
}).call(a)

--Aaron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top