Help with nokogiri

I’m trying to work with nokogiri but I have some problems
I need to iterate a string that has several tags with a base64
and change it for a url


test</ p><img
alt = \ “”> bla bla bla <img
src=“data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA…” alt = \ “”>”

Change to:

test</ p><img src=“” alt = \ “”> bla bla bla
<img src=“” alt = \ “”>”

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


Well, I managed to this:

doc = Nokogiri::HTML::DocumentFragment.parse(string)
doc.css('img').map { |i| i.set_attribute(:src,”)
p doc.to_s

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs