OgaRuby 的 XML/HTML 解析器
Oga 是一个 Ruby 的 XML/HTML 解析器。
示例代码1:
require 'oga' require 'net/http' body = Net::HTTP.get(URI.parse('http://www.reddit.com/')) document = Oga.parse_html(body) titles = document.xpath('//div[contains(@class, "entry")]/p[@class="title"]/a/text()') titles.each do |title| puts title.text end
示例代码2:
Oga.parse_xml('<people>foo</people>', :strict => true) # works fine Oga.parse_xml('<people>foo', :strict => true) # throws an error
评论