You are right, the problem is text . text returns the text between the opening tag and the closing tag. Since the meta tags are empty, this gives an empty string. Instead, you want to use the value of the "content" attribute.
doc.xpath("//meta[@name='Keywords']/@content").each do |attr| puts attr.value end
Since you know that there will be only one meta tag named โkeywordsโ, you actually do not need to scroll through the results, but it can wrap the first element as follows:
puts doc.xpath("//meta[@name='Keywords']/@content").first.value
Please note, however, that this will lead to an error if the meta tag does not contain the name โcontentโ, so the first option may be preferred.
source share