Peter Szinek
11/11/2008 1:50:00 PM
On 2008.11.11., at 14:22, soldier.coder wrote:
> I have the following code:
>
> require 'open-uri'
> def scrape_table(html)
> %r{</thead.*?>(.*?)</table>}m =~html
> $1
> end
>
> def scrape_case(a_line)
> %r{(<a\s.*?\d{6}-\d{2}'>\d{6}-\d{2}<\/a>)}m =~ a_line
> $1
> end
> Is there any way I can grab all those links into an array?
Sure - String#scan is your friend:
def scrape_case(a_line)
a_line.scan(/<a\s.*?\d{6}-\d{2}'>\d{6}-\d{2}<\/a>/)
end
ex:
>> "<a href='123456-78'>123456-78</a> here is another: <a
href='111111-99'>111111-99</a>".scan(/<a\s.*?\d{6}-\d{2}'>\d{6}-\d{2}<
\/a>/)
=> ["<a href='123456-78'>123456-78</a>", "<a
href='111111-99'>111111-99</a>"]
HTH,
Peter