How can I remove <img>
tags using Nokogiri?
I have the following code but it wont work:
# str = '<img src="canadascapital.gc.ca/data/2/rec_imgs/5005_Pepsi_H1NB.gif"/…; testt<a href="#">test</a>tfbu'
f = Nokogiri::XML.fragment(str)
f.search('//img').each do |node|
node.remove
end
puts f
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…