class Ruboty::YMCrawl::Page
あるURLから取得できるHTMLドキュメントを抽象化したクラス
Public Class Methods
new(url)
click to toggle source
# File lib/ruboty/ymcrawl/crawler.rb, line 57 def initialize(url) @url = url @doc = get_doc end
Public Instance Methods
search_elements(selector)
click to toggle source
指定したcssセレクタに合致する要素を表すクラスの配列を返す
# File lib/ruboty/ymcrawl/crawler.rb, line 63 def search_elements(selector) @doc.css(selector).map{ |doc| Element.new(doc) } end
Private Instance Methods
get_doc()
click to toggle source
与えられたURLをパースして返す
# File lib/ruboty/ymcrawl/crawler.rb, line 67 def get_doc puts "get_doc from #{@url}" HostManager.instance.wait(@url) html = open(URLUtil.normalize_url(@url), "r:binary").read Nokogiri::HTML(html.toutf8, nil, 'utf-8') rescue OpenURI::HTTPError => ex puts "failed URL: #{@url}" puts "HTTP Error message: #{ex.message}" raise PageError.new(ex.message) end