delegate css method to page's parser
parent
d4d4cc97b3
commit
715fbfabb7
6
main.cr
6
main.cr
|
@ -4,6 +4,6 @@ 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.parser.not_nil!.css("h1").first.inner_text
|
puts page.css("h1").first.inner_text
|
||||||
|
|
|
@ -2,13 +2,13 @@ require "myhtml"
|
||||||
require "./file"
|
require "./file"
|
||||||
|
|
||||||
class MechanizeCr::Page < MechanizeCr::File
|
class MechanizeCr::Page < MechanizeCr::File
|
||||||
|
delegate :css, to: parser
|
||||||
|
|
||||||
def initialize(uri, response, body, code)
|
def initialize(uri, response, body, code)
|
||||||
super(uri, response, body, code)
|
super(uri, response, body, code)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parser
|
def parser : Myhtml::Parser
|
||||||
return @parser if @parser
|
@parser ||= Myhtml::Parser.new(@body)
|
||||||
return unless @body
|
|
||||||
@parser = Myhtml::Parser.new(@body)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue