From: Justin Bailey Date: 2006-03-02T01:43:20+09:00 Subject: Re: [Newbie] Getting data from html-ish like crap. ------=_Part_317_16517320.1141231381682 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline First, don't use Net::HTTP. Require 'open-uri' at the top and you can simplify your code a lot: open(https://www.knightonlineworld > > .com/index.php?pg=3Drankings&sub=3D2&radServer=3D1&clanid=3D12199) do |pa= ge| html =3D page.gets(nil) end Which will get the whole document into the 'html' variable. Next, look at StringScanner and using regular expressions. It will allow yo= u to iterate through your document quickly and pick up the columns you want. Some pseudo-code might look like: scanner =3D StringScanner.new while scanner.check(/.*(.*)<\/td>.*.*<\/td>.*.*<\/td>.*= (.*)<\/td>.*/m) do name =3D scanner[1] points =3D scanner[2] end That will extract the name and level from each row. The parantheses in the regular expression are "capture groups", and they relate to the assignments in the loop (name =3D scanner[1], points =3D scanner[2]). The 'm' following= the regular expression makes sure a multi-line match is performed, which is probably necessary as the table cells are on different lines. For further syntax and library help check http://www.ruby-doc.org. Especially check out the 'Programming Ruby' book and read up Ruby's regular expressions, if you aren't familiar with them. Hope that helps! On 3/1/06, spam_monkey <"sidhellfire(spam_monkey)"@o2.pl> wrote: > > Hi, > I wanted to learn something, and choosed ruby, > since it looked awesome, and can't say it isn't. > I am not expierienced programmer (tried some > Pascal, then PHP), and decided to do something > small, but usefull. Let's get straight into the > problem. > > At the url: > > https://www.knightonlineworld.com/index.php?pg=3Drankings&sub=3D2&radServ= er=3D1&clanid=3D12199 > I've got something similar to html (at least > it's not table based, but still damn ugly code > there) with online statistics. > > I don't want to parse that one, i just want to > 'crop that crap' and retrive informations from > data inside one element a div with an > id=3D"bleet". There are tables in there, but seems > impossible to navigate there. > > I am really suck at strings :( > > > Quatrina # i want this > 52 # > Shaman # > 563 # and this one > # preferable everything :P > > I would want to hash that data, to have it > usefull in future (aiming a rails app in > future), but selecting two columns in each row, > located in the last table in the id'ed element > placed in not-well-made document looks > impossible for me. I don't even know where to > start, and it's FAR away from the things i > wanted to do (counting numbers*, assinging > additional data). > > > All i've done already is getting the document: > > > require 'uri' > > require 'net/http' > > > > trg =3D " > https://www.knightonlineworld.com/index.php?pg=3Drankings&sub=3D2&radServ= er=3D1&clanid=3D12199 > " > > puts 'processing' + cel + " :\n" > > > > r =3D Net::HTTP.get_response(URI.parse(trg).host, URI.parse(trg).path) > > > > puts r.body > > > Thanks for reading. > > */Notice it does count "Loyality" wrong/ > > ------=_Part_317_16517320.1141231381682--