读书人

Programming Ruby(读书笔记)-11章(基准

发布时间: 2014-01-15 15:40:23 作者: rapoo

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

?

读书人网 >编程

热点推荐