You should try to be a little more defensive here by doing the following:

`link[0]['href'] rescue nil`