add page title

This commit is contained in:
Kanezoh 2021-05-05 11:49:14 +09:00
parent 715fbfabb7
commit 52b77131dc
2 changed files with 8 additions and 3 deletions

View File

@ -4,6 +4,7 @@ agent = Mechanize.new
agent.request_headers = HTTP::Headers{"Foo" => "Bar"} agent.request_headers = HTTP::Headers{"Foo" => "Bar"}
params = {"hoge" => "hoge"} params = {"hoge" => "hoge"}
page = agent.get("http://example.com/", params: params) page = agent.get("http://example.com/", params: params)
puts page.code #puts page.code
puts page.body #puts page.body
puts page.css("h1").first.inner_text #puts page.css("h1").first.inner_text
puts page.title

View File

@ -11,4 +11,8 @@ class MechanizeCr::Page < MechanizeCr::File
def parser : Myhtml::Parser def parser : Myhtml::Parser
@parser ||= Myhtml::Parser.new(@body) @parser ||= Myhtml::Parser.new(@body)
end end
def title
title = parser.css("title").first.inner_text
end
end end