add parser
parent
b57dd534ac
commit
d4d4cc97b3
5
main.cr
5
main.cr
|
@ -4,5 +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
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
|
require "myhtml"
|
||||||
require "./file"
|
require "./file"
|
||||||
|
|
||||||
class MechanizeCr::Page < MechanizeCr::File
|
class MechanizeCr::Page < MechanizeCr::File
|
||||||
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
|
||||||
|
return @parser if @parser
|
||||||
|
return unless @body
|
||||||
|
@parser = Myhtml::Parser.new(@body)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue