Forum: Ruby Hpricot question - how to modify a tag attribute

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
4087fa40d402c6418774c115347c1dd8?d=identicon&s=25 ciocan (Guest)
on 2007-06-29 17:30

How can I modify a tag attribute using Hpricot ?


url = ''
doc = Hpricot(open(url))

I want to replace from all <img> tags the property src = "imagexxx.jpg"
with src = "imageyyy.jpg"

Bf6862e2a409078e13a3979c00bba1d6?d=identicon&s=25 Gregory Seidman (Guest)
on 2007-06-29 17:37
(Received via mailing list)
On Sat, Jun 30, 2007 at 12:30:24AM +0900, ciocan wrote:
> with src = "imageyyy.jpg"
(doc/'img').each { |e| e['src'].sub!('imagexxx.jpg', 'imageyyy.jpg') }

> Thanks
This topic is locked and can not be replied to.