Shadowfirebird
7/25/2008 7:50:00 AM
I'll second that. Hpricot is really quite remarkable. It'll almost
certainly save you days and days of pain. Unless you are doing this
for fun / learning, of course.
On Fri, Jul 25, 2008 at 8:44 AM, Srijayanth Sridhar
<srijayanth@gmail.com> wrote:
> Any specific reason you can't use hpricot or other HTML parsers?
>
> Jayanth
>
> On Fri, Jul 25, 2008 at 1:09 PM, touffik@gmail.com <touffik@gmail.com> wrote:
>> Hi folks,
>> I'm trying to code a ruby script that select the content of a HTML
>> table in a HTML page.
>> I used rubular to test my regexp syntax which is
>> / <td class="TabIntCenContenuto"[^>]*>(.*) /
>> with rubular the result of my expression is :
>> Result 1
>> 1. 12345678
>> Result 2
>> 1. SAN FRANCESCO DA PAOLA
>> Result 3
>> 1. Via San Francesco Da Paola, 10
>> Result 4
>> 1. 10123
>> Result 5
>> 1. TORINO
>> etc....
>> But with my script :
>>
>> File.open('D:/testt/1.txt', 'r') do |filein|
>>
>> while line = filein.gets
>> p line if line =~ /<td class="TabIntCenContenuto"[^>]*>/ .. line
>> =~ /\/A /
>> end
>> fileout.puts p
>> end
>> end
>>
>> I got this result
>> "</td><td class=\"TabIntCenContenuto\">12345678 \n"
>> "</td><td class=\"TabIntCenContenuto\">SAN FRANCESCO DA PAOLA </
>> td>\n"
>> "<td class=\"TabIntCenContenuto\">Via San Francesco Da Paola,
>> 10 </td>\n"
>> "<td class=\"TabIntCenContenuto\">10123 </td>\n"
>> "<td class=\"TabIntCenContenuto\" align=\"left\">TORINO </td>\n"
>>
>> I thought the .. between 2 "line =~" was like (...) in rubular which
>> let catch the content ??
>> Moreover I would like to transform this html code in XML. But I can"t
>> find an idea how to transform these HTML line in XML.
>> <root>
>> <number>12345678</number>
>> But there is no attribut 'name' or wathever in the <td> so making and
>> match/replace would be difficult ?
>> ..
>>
>> So, if someone can help me I would be very grateful.
>> Nice day ;)
>>
>>
>
>
--
Me, I imagine places that I have never seen / The colored lights in
fountains, blue and green / And I imagine places that I will never go
/ Behind these clouds that hang here dark and low
But it's there when I'm holding you / There when I'm sleeping too /
There when there's nothing left of me / Hanging out behind the
burned-out factories / Out of reach but leading me / Into the
beautiful sea