Oga是一个Ruby的XML/HTML解析器。
示例代码1:
require 'oga'require 'net/http'body = Net::HTTP.get(URI.parse('https://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.textend示例代码2:
Oga.parse_xml('<people>foo</people>', :strict => true) # works fineOga.parse_xml('<people>foo', :strict => true) # throws an error
评论