Nokogiri Meta Tags Meta Keywords Extraction

Extract Meta Tags and Meta Keywords with Nokogiri

Introducing how to extract HTML meta tags and meta keywords used for SEO using Nokogiri, a scraping library in the Ruby programming language. <pre><code>doc = Nokogiri::HTML(page.body)...

Shou Arisaka
1 min read
Nov 14, 2025

Introducing how to extract HTML meta tags and meta keywords used for SEO using Nokogiri, a scraping library in the Ruby programming language.

doc = Nokogiri::HTML(page.body)

doc.at("meta[name='keywords']")['content']
# or
doc.xpath('//meta[@name="keywords"]/@content').text

The above program is executed in the following steps:

  • Parse HTML with the Nokogiri::HTML method
  • Get the element with the meta tagโ€™s name attribute being keywords using the at method
  • Get the value of the content attribute

Also, to get the element with the meta tagโ€™s name attribute being description, use the following:

doc.at("meta[name='description']")['content']

Share this article

Shou Arisaka Nov 14, 2025

๐Ÿ”— Copy Links