XPath to Parse "SRC" from IMG tag?

You are so close to answering this yourself that I am somewhat reluctant to answer it for you. However, the following XPath should provide what you want (provided the source is XHTML, of course).

//img[@class='photo-large']/@src

For further tips, check out W3 Schools. They have excellent tutorials on such things and a great reference too.


Using Hpricot this works:

doc.at('//img[@class="photo-large"]')['src']

In case you have more than one image, the following gives an array:

doc.search('//img[@class="photo-large"]').map do |e| e['src'] end

However, Nokogiri is many times faster and it “can be used as a drop in replacement” for Hpricot.
Here the version for Nokogiri, in which this XPath for selecting attributes works:

doc.at('//img[@class="photo-large"]/@src').to_s

or for many images:

doc.search('//img[@class="photo-large"]/@src').to_a