delegate css method to page's parser

master
Kanezoh 2021-05-04 13:42:58 +09:00
parent d4d4cc97b3
commit 715fbfabb7
2 changed files with 7 additions and 7 deletions

View File

@ -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

View File

@ -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