[Mechanize-users] Migrate from Hpricot to Nokogiri
aaron.patterson at gmail.com
Thu Jun 18 12:47:22 EDT 2009
On Wed, Jun 17, 2009 at 7:55 PM, Jonathan
Huizingh<jhuizingh at mindless.com> wrote:
> I was using Mechanize with Hpricot in a rails app about 6 months ago.
> I recently started to work on that app again, and was getting an
> error: "undefined method `text' for #<Array:0x7f8b0d349be0>". It
> took me a little bit of research, but I figured out that I was using a
> newer version of the Mechanize gem on this machine and that it had
> switched to using Nokogiri as its parser.
Yes! Your problem isn't to do with hpricot vs nokogiri, but that the
links api has changed. "links" returns a normal array now, so you
can't call "text" on it.
> I would like to update my code to use Nokogiri since it is now the
> default. I have been looking around the documentation, but haven't
> been able to find any examples of what I am trying to do. Can
> somebody give me an example of how I would update the following line?
> unless logged_in_page.links.text(/link text to find/).length > 0
> ... more code here ...
unless logged_in_page.links_with(:text => /link text to find/).length > 0
> I also saw that there were Hpricot decorators for Nokogiri objects. I
> assume this would allow me to use my Hpricot code as-is, but I
> couldn't find an example of how to do that. Could somebody give me an
> example of that?
If you're only calling methods on mechanize, you shouldn't need to do that.
More information about the Mechanize-users