Edit img tags in html document with nokogiri ruby -


i wanting edit img tags within html document using nokogiri.

i have example following img tag in doc:

<img src="image1.jpg">

there no consistency naming of images. want convert above img following:

<img src="/user/account/folder1/folder2/image1.jpg">

i have /user/account/folder1/folder2/ stored in variable example.

the document can have 1 20 image tags within each document path same.

at end of conversion want take amended html , store variable

  doc = nokogiri::html(open(file)) 

i able open doc unsure how proceed further iterating on it.

can help?

ended achieving wanted with:

page = nokogiri::html(open(file))   page.css('img').each |div|     image = div.attribute("src")     div.set_attribute("src", ("#{absolute_path}""#{image}") )     puts div.attribute("src")   end    amended_page = page.to_html 

its worth noting absolute_path variable set outside of , typically user/account/folder/


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -