diff --git a/main.cr b/main.cr index cd0a922..619732d 100644 --- a/main.cr +++ b/main.cr @@ -4,6 +4,7 @@ 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.css("h1").first.inner_text +#puts page.code +#puts page.body +#puts page.css("h1").first.inner_text +puts page.title diff --git a/src/mechanize/page.cr b/src/mechanize/page.cr index bb04f4a..75a2447 100644 --- a/src/mechanize/page.cr +++ b/src/mechanize/page.cr @@ -11,4 +11,8 @@ class MechanizeCr::Page < MechanizeCr::File def parser : Myhtml::Parser @parser ||= Myhtml::Parser.new(@body) end + + def title + title = parser.css("title").first.inner_text + end end