如何使用 Nokogiri 获取元关键字? [英] How to get Meta Keywords using Nokogiri?

查看:40
本文介绍了如何使用 Nokogiri 获取元关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Nokogiri 进行作业,我正在努力解决这个问题.它在伤害我的大脑.任何导致解决方案的步骤、提示或示例都会很可爱.

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.

推荐答案

这是一个简单的例子:

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

这篇关于如何使用 Nokogiri 获取元关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆