PHP get_meta_tags.
我希望阅读给定网址的元标记信息
答案 0 :(得分:4)
您可以尝试使用Hpricot并执行以下操作:
doc = Hpricot(URI.parse("http://example.com/").read)
(doc/'/html/head/meta')
#=> Elements[...]
答案 1 :(得分:2)
非常感谢。
它对我有用。我正在尝试获取描述形式元标记。 我的代码就像
def self.extract_description_from_url(url)
description = ""
doc = Hpricot(URI.parse(url).read)
(doc/'/html/head/meta').each do |meta|
val= meta.get_attribute('name')
if val == "description"
description = meta.get_attribute('content')
end
end
return description
end