Search code examples
rubymechanizemechanize-ruby

How to get page description with ruby mechanize?


How do I get page descriptions with Mechanize?

The Pismo gem has this functionality, but it's worse than the Mechanize gem. Mechanize finds image tags, for example.

I didn't find in the Mechanize documentation how to get the description.

Does anyone know a better plugin or how I can do that?


Solution

  • Try this:

    node = page.at("head meta[name='description']")
    description = node["content"]
    

    (node is an Nokogiri::XML::Node.)