Ruby on Rails Wednesday, June 3, 2015

Well, I managed to this:

    doc = Nokogiri::HTML::DocumentFragment.parse(string)
    doc.css('img').map { |i| i.set_attribute(:src, "http://www.blabla.com") }
    p doc.to_s

On Wednesday, June 3, 2015 at 9:44:00 AM UTC-3, Gm wrote:
I'm trying to work with nokogiri but I have some problems
I need to iterate a string that has several tags <img> with a base64 image and change it for a url

example:

"<p>test</ p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA..." alt = \ "\"> bla bla bla <img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA..." alt = \ "\">"

Change to:

"<p>test</ p><img src=\"http:www.blablabla.com" alt = \ "\"> bla bla bla <img src=\"http:www.blablabla.com" alt = \ "\">"

How can I select these img tags, change the src content and return the same string modified ?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/64daf2cf-e62e-40f3-99fe-d8b13d3c1c3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment