screen scraping programaticprogrammer.com ?

7

7stud --

The following is from "Programming Ruby 2nd" p.133:

----
require "net/http"

h = Net::HTTP.new("www.programaticprogrammer.com", 80)
response = h.get("/index.html")

if response.message == "OK"
puts response.body.scan(/<img src="(.*?)"/m).uniq
end
----

It doesn't work: nothing is printed. So, I modified it a little:

-----
require "net/http"

h = Net::HTTP.new("www.programaticprogrammer.com", 80)
response = h.get("/index.html")

puts response.message
puts response.code

if response.message == "OK"
puts "*"
puts response.body.scan(/<img src="(.*?)"/m).uniq
end
-----

and the output was:

Found
302


I clicked a link on their home page and tried to access the page that
was displayed, but I got the same result. What am I doing wrong?
 
R

Ronald Fischer

h =3D Net::HTTP.new("www.programaticprogrammer.com", 80)
response =3D h.get("/index.html")
=20
puts response.message
puts response.code
=20
if response.message =3D=3D "OK"
puts "*"
puts response.body.scan(/<img src=3D"(.*?)"/m).uniq
end
-----
=20
and the output was:
=20
Found
302
=20
=20
I clicked a link on their home page and tried to access the page that
was displayed, but I got the same result. What am I doing wrong?

Wrong URL. How about using www.pragmaticprogrammer.com instead?

I think the prOGRamatic programmers are slowly dying out anyway in
favour of the pragmatic programmers.... ;-)

Ronald
--=20
Ronald Fischer <[email protected]>
Phone: +49-89-452133-162
 
J

John Joyce

Just remember that with screen scraping, you are anticipating a file
served by a file server, on top of that you are generally
anticipating a very particular structure in that document. Web sites
change frequently and without notice and even the smallest changes
can blow out your scraper. So be very careful to inspect the various
pages of sites you plan to scrape, and then try to write your scraper
to check for things and not fail if it isn't found.

With some clever programming and a little knowledge of the site, you
can make a simple but smart scraper. However, it will still be pretty
fragile. html/xhtml is just too loose and human-language like, full
of ambiguity and implicit meaning that humans would get, but machines
would work hard to fail at.
 

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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top