2012-03-04 2 views
8

Nokogiri를 과제물로 사용하고 있으며이를 파악하는 데 어려움을 겪고 있습니다. 그것은 내 두뇌를 아프게합니다. 솔루션으로 이어지는 모든 단계, 힌트 또는 예는 멋질 것입니다. 단지 어쩌면 doc.at, 일있을 예정이기 때문에Nokogiri를 사용하여 메타 키워드를 얻는 방법은 무엇입니까?

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 

답변

16

은 간단한 예입니다 , 잘못된. 대소 문자를 구분해야합니다. metaKeywords = doc.xpath ('// 메타 [case_insensitive_equals (@name, "keywords")], XpathFunctions.new) [0] .attributes [ "content"]. value
+5

가 ('메타 [이름 @ = "키워드"]') : 내용] 더 의미 – pguardiario

+0

아니하게 여기 –

관련 문제