How to get Meta Keywords using Nokogiri?

2020-06-15 12:28发布

I'm using Nokogiri for an assignment and I'm struggling to figure this out. It's hurting my brain. Any steps, hints, or examples leading to the solution would be lovely.

标签: ruby nokogiri
1条回答
老娘就宠你
2楼-- · 2020-06-15 12:54

Here is a simple example:

require 'rubygems'
require 'nokogiri'


doc = Nokogiri::HTML("<html><head><meta name=\"Keywords\" content=\"one, two, three\"></head><body></body></html>")

doc.xpath("//meta[@name='Keywords']/@content").each do |attr|
  puts attr.value
end
查看更多
登录 后发表回答