diff --git a/main.cr b/main.cr index fbfa943..2197a14 100644 --- a/main.cr +++ b/main.cr @@ -4,5 +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.code +#puts page.body +puts page.parser.not_nil!.css("h1").first.inner_text diff --git a/src/mechanize/page.cr b/src/mechanize/page.cr index e9b56ef..72826c3 100644 --- a/src/mechanize/page.cr +++ b/src/mechanize/page.cr @@ -1,6 +1,14 @@ +require "myhtml" require "./file" + class MechanizeCr::Page < MechanizeCr::File 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) + end end