Gregory Seidman wrote: > On Mon, Dec 25, 2006 at 04:24:05PM +0900, bbiker wrote: > [...] > } Thank you for your offer of assistance > > Sure. > > } In simple term I need to extract text from a <p ..... /p> element ... > } yes I know that I can use "traverse_text" That works fine except when > } there is no text at an expected location. > [...] > } An alternate way would be to simply insert arbritary text ('x ") after > } the img element... no need to extract the basename. .. the s h d c > } sequence is constant. > } > } This would let traverse_text yield "x 8 7 6 2", "x ", "x K 7 6 4", "x Q > } 7 6 3 2" > } A single character (x) would also work. > } Actually, I prefer the alternate way...Occam's Razor > > You got it. > > } I know that I can do both using regexp. but I am trying to learn and > } understand hpricot. > } I understand that hpricot can modify (edit), remove, and add elements. > } It is definitely stronger and faster. It also offers a more generic way > } of processing html files. > } > } So in simple terms, the problem is how to insert text after an element. > > Here's some code that should help you on your way. You'll notice that I'm > avoiding adding methods to Hpricot classes and instead pulling out the > extra methods into modules and calling extend on the appropriate objects. > Assuming you've loaded a document into the variable doc, > doc.extend(Hpricot::InsertTextExtension).insert_text_after('x ', 'img') > will make the changes you want: > == CODE removed to save bandwidth Thank you very much for your assistance. I have just read the code and it seems to do exactly what I want .. I have not yet tested it out. I must admit that I do not understand the details but I will study the code to understand exactly the "how" it does .. I know "what" it does. I will let you know how it actually worked out. Let me say that I would have been unable to come up with your solution. So Greg once again, THANK YOU VERY MUCH ... Happy Holidays