diff --git a/main.cr b/main.cr index 2197a14..cd0a922 100644 --- a/main.cr +++ b/main.cr @@ -4,6 +4,6 @@ agent = Mechanize.new agent.request_headers = HTTP::Headers{"Foo" => "Bar"} params = {"hoge" => "hoge"} page = agent.get("http://example.com/", params: params) -#puts page.code -#puts page.body -puts page.parser.not_nil!.css("h1").first.inner_text +puts page.code +puts page.body +puts page.css("h1").first.inner_text diff --git a/src/mechanize/page.cr b/src/mechanize/page.cr index 72826c3..bb04f4a 100644 --- a/src/mechanize/page.cr +++ b/src/mechanize/page.cr @@ -2,13 +2,13 @@ require "myhtml" require "./file" class MechanizeCr::Page < MechanizeCr::File + delegate :css, to: parser + def initialize(uri, response, body, code) super(uri, response, body, code) end - def parser - return @parser if @parser - return unless @body - @parser = Myhtml::Parser.new(@body) + def parser : Myhtml::Parser + @parser ||= Myhtml::Parser.new(@body) end end