Sha256: 99a858fbb7e192821d2b2ad587f050c344d44a66e26e4f63319b453f206b1c57
Contents?: true
Size: 1.19 KB
Versions: 2
Compression:
Stored size: 1.19 KB
Contents
#!/usr/bin/env ruby # -*- coding: utf-8 -*- # Author:: TAC (tac@tac42.net) require 'pp' require 'time' require 'mechanize' require_relative 'lib/yasuri/yasuri' agent = Mechanize.new uri = "http://www.asahi.com/" # Node tree constructing by DSL root = links_top '//*[@id="MainInner"]/div[1]/ul/li/a' do text_title '//*[@id="MainInner"]/div[1]/div/h1' text_article '//*[@id="MainInner"]/div/div[@class="ArticleText"]' end # Node tree constructing by JSON src = <<-EOJSON { "node" : "links", "name" : "root", "path" : "//*[@id='MainInner']/div[1]/ul/li/a", "children" : [ { "node" : "text", "name" : "title", "path" : "//*[@id='MainInner']/div[1]/div/h1" }, { "node" : "text", "name" : "article", "path" : "//*[@id='MainInner']/div/div[@class='ArticleText']" } ] } EOJSON root = Yasuri.json2tree(src) # Access to parsed resources page = agent.get(uri) contents = root.inject(agent, page) contents.each do |h| t = h['title'] a = h['article'] puts t puts a puts "=" * 100 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
yasuri-0.0.3 | app.rb |
yasuri-0.0.2 | app.rb |