Programming Ruby(读书笔记)-11章(标准输入输出)
require 'open-uri'require 'nokogiri'doc = Nokogiri::HTML(open("http://pragprog.com/"))puts"Pagetitleis"+doc.xpath("//title").inner_html#Output the first paragraph in the div with an id="copyright"#(nokogiri supports both xpath and css-like selectors)puts doc.css('div#copyright p')#Output the second hyperlink in the site-links div using xpath and cssputs "\nSecond hyperlink is"puts doc.xpath('id("site-links")//a[2]')puts doc.css('#site-links a:nth-of-type(2)')
?Nokogiri can also update and create HTML and XML
?