Hey William!
On Mon, Jan 14, 2008 at 10:25:16AM -0500, William Flanagan
wrote:> All,
>
> Been a while since I''ve "mechanized" and I''m
running into an idiot simple
> problem. I''m looking for more detailed examples to refresh my
memory.
>
> My question is how to get a list of links off of a page based on
information
> in the img src attribute, specifically if the img tag contains a
> "mp3.gif/jpg".
> I, for the life of me, can''t seem to remember how to do this.
>
> And, as I go through this exercise, I am sure I will run into other issues
> as well. So, if anyone has any good sources for examples, I''d
love to see
> them.
Give something like this a try:
agent = WWW::Mechanize.new
page = agent.get(''http://localhost/~aaron/test.html'')
links = page.search(''//a'').select { |link|
img = link.search(''//img'').first
img && img[''src''] =~ /mp3\.(gif|jpg)/
}
Page can be searched like Hpricot, and links found through that interface can
be clicked. So feel free to get specific with your Hpricot queries.
--
Aaron Patterson
http://tenderlovemaking.com/