From: Alex Stahl Date: 2010-10-06T05:53:02+09:00 Subject: Re: How can I count number of elements in an HTML page Nokogiri allows direct access to HTML elements as data. I use it a lot in my work. Try something like: require 'nokogiri' page = Nokogiri::HTML response.body count = 0 page.xpath("//div[@class='first section']).each do |element| count += 1 if element.xpath("/ul") end Or something along those lines... (I didn't test this first). On Tue, 2010-10-05 at 15:45 -0500, Paul wrote: > Hi there, I'm using net/http to retrieve some html pages and now I > want to count the number of items in a list on the page. The > response.body is stored as a string. > > The HTML looks something like this: > ---- >
>

> Section Heading I'm interested in: >

> >
> >