How to get Meta Keywords using Nokogiri?

ぃ、小莉子 提交于 2019-12-09 10:40:36

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/9554053/how-to-get-meta-keywords-using-nokogiri

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!