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"}
|
||||
params = {"hoge" => "hoge"}
|
||||
page = agent.get("http://example.com/", params: params)
|
||||
#puts page.code
|
||||
#puts page.body
|
||||
puts page.parser.not_nil!.css("h1").first.inner_text
|
||||
puts page.code
|
||||
puts page.body
|
||||
puts page.css("h1").first.inner_text
|
||||
|
|
|
@ -2,13 +2,13 @@ require "myhtml"
|
|||
require "./file"
|
||||
|
||||
class MechanizeCr::Page < MechanizeCr::File
|
||||
delegate :css, to: parser
|
||||
|
||||
def initialize(uri, response, body, code)
|
||||
super(uri, response, body, code)
|
||||
end
|
||||
|
||||
def parser
|
||||
return @parser if @parser
|
||||
return unless @body
|
||||
@parser = Myhtml::Parser.new(@body)
|
||||
def parser : Myhtml::Parser
|
||||
@parser ||= Myhtml::Parser.new(@body)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue