From 52b77131dc163a74b756606bce91ebace237aee7 Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Wed, 5 May 2021 11:49:14 +0900 Subject: [PATCH] add page title --- main.cr | 7 ++++--- src/mechanize/page.cr | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) 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