Forum: Ruby tag and attribute in Nokogiri

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
73700e119917433681f2e8f3e4369f74?d=identicon&s=25 Li CN (alex-osu3)
on 2016-09-09 15:19
Hi all,

Just a quick question: I want to extract some info from one webpage.
How do I return all <img> tag that contains id attribute that contains
'my_img'?

Enclosed is one example for the format in my webpage and part of my
script.

doc = Nokogiri::HTML(open(fn))
puts doc.search('img[@id]')

My script will return all <img> with id attribute. But I would like to
return the first 3 <img> ONLY.

Thanks,



===================
<img alt="" src="http://abcxyz.com" id="my_img8">
<img alt="" src="http://abcxyz.com" id="my_img9">
<img alt="" src="http://abcxyz.com" id="my_img10">

<img alt="" src="http://abcxyz.com" id="img10">
<img alt="" src="http://abcxyz.com" id="my">
This topic is locked and can not be replied to.