add parser

master
Kanezoh 2021-05-04 09:56:02 +09:00
parent b57dd534ac
commit d4d4cc97b3
2 changed files with 11 additions and 2 deletions

View File

@ -4,5 +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.code
#puts page.body
puts page.parser.not_nil!.css("h1").first.inner_text

View File

@ -1,6 +1,14 @@
require "myhtml"
require "./file"
class MechanizeCr::Page < MechanizeCr::File
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)
end
end