add page title
This commit is contained in:
parent
715fbfabb7
commit
52b77131dc
7
main.cr
7
main.cr
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user