Thank u i have done what u told using gsub operator i replaces the tags to
the form as u told,but problem is that
if
doc = Hpricot(open('Delhi.txt'))
x=doc.to_s
doc1=x.gsub(/<(\/?)li><span>/,'</li></see><see><span>')
puts doc1
doc1.search('span').each do |y|
puts y.inner_text
end
its giving error
undefined method `search' for #<String:0xb7d0bc74> (NoMethodError)
because doc1 is string how can i conevrt so that i can read the file again
by hpricot
Regards
Prashanth Hiremath
On Wed, Sep 9, 2009 at 10:38 PM, Ar Chron
<[email protected]>wrote:
>
> Your html is still flat, so you have to work with the patterns that you
> see.
> You have:
> span
> li
> li
> li
> span
> li
> li
> li
> etc...
>
> An ugly, brute force, one case solution is to:
>
> read the page with Hpricot
> remove the header
> convert it to a simple string representation
> stick your opening tag '<see>' at the head
> stick your closing tag and a div end '</div></see>' at the tail
> change all '<span>' to '</div><div><span>'
> doctor up the new head from '<see></div><div>' to just '<see><div>'
> re-create your Hproicot doc from the modified string
>
> which takes about 8 lines of code.
>
> YMMV
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---