hpricot:An Hpricot Showcase:Hpricot Challenge:Selecting part of a String with Dynamic Contents

まんま

>> require "hpricot"
=> true
>> doc = Hpricot('<a href="out.php?id=1112&url=www.website.com"></a><a href="out.php?id=2232&url=www.website.com"></a><a href="out.php?id=3346&url=www.website.com"></a>')
=> #<Hpricot::Doc {emptyelem <a href="out.php?id=1112&url=www.website.com">} {emptyelem <a href="out.php?id=2232&url=www.website.com">} {emptyelem <a href="out.php?id=3346&url=www.website.com">}>
>> require "cgi"
=> true
>> doc.search('a[@href]').map { |x| CGI.parse(x['href'][/\?.+/][1..-1])['id'].first }
=> ["1112", "2232", "3346"]