Peter Szinek wrote:

> Hello,
> 
>> Digression: when solving a problem like this, it is often much easier to
>> write a few lines of HTML than to try to use a high-powered library to
>> accomplish it.
> 
> I don't see why is it an advantage here.

You may not have noticed the degree to which the sample data varied from
cell to cell, and at times fails to match up with your named fields.

> The first solution in this 
> thread:
> 
> -------------------------------------------------------------------
> Record = Struct.new("Record", :name, :date, :name_again, :some_num,
> :buy_link, :some_num2, :letters, :price)
> records = []
> 
> cells = Hpricot(doc)/"/table/tr/td"
> 
> cells.map { |elem| elem.inner_html }.each_slice(8) do |slice|
>   records << Record.new(*slice)
> end
> 
> p records.sort_by {|record| record.price.slice(1..record.size) }
> ------------------------------------------------------------------
> 
> is shorter, does not care about malformed HTML and even does the sorting
> which I believe was the main intention of the OP. So why not use a
> high-powered library?

In some cases this is not the best approach. My reply was meant to make the
OP aware of this fact.

> I do not argue that parsing the page with regexps and seeing what's
> going on under the hood can provide a lot of experience, but I am really
> sure that feeding a real life page to a HTML parser is safer than to use
> the regexp approach.

My point is simple. People who consider using a large library to meet a need
like this may not be aware that a simple solution exists. Sometimes a
simple solution is better, for example in the case of an environment with
limited resources. Also, the OP doesn't need to download and install Ruby,
but he may well have to download and install Hpricot.

Then, having been made aware of more than one option, the OP can make a more
informed decision.

In this case, the OP has the option of learning how to talk to Hpricot, or
he can learn how to talk to Ruby. The difficulty level is in the same order
of magnitude if not closer, and I have again said what I normally say in a
case like this, and in the same way -- in essence, here is an option you
may not be aware of.

-- 
Paul Lutus
http://www.arachnoid.com