modeling node
parent
bd90c4032c
commit
2813e989a9
11
main.cr
11
main.cr
|
@ -2,11 +2,12 @@ require "./src/mechanize.cr"
|
||||||
|
|
||||||
agent = Mechanize.new
|
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("https://kowabana.jp/users/sign_in/", params: params)
|
||||||
query = {"foo" => "foo_value", "bar" => "bar_value"}
|
page.forms
|
||||||
page = agent.post("http://example.com/", query: query)
|
#query = {"foo" => "foo_value", "bar" => "bar_value"}
|
||||||
|
#page = agent.post("http://example.com/", query: query)
|
||||||
#puts page.code
|
#puts page.code
|
||||||
puts page.body
|
#puts page.body
|
||||||
#puts page.css("h1").first.inner_text
|
#puts page.css("h1").first.inner_text
|
||||||
#puts page.title
|
#puts page.title
|
||||||
|
|
|
@ -5,13 +5,15 @@ class MechanizeCr::Form
|
||||||
getter fields : Array(MechanizeCr::FormContent::Field)
|
getter fields : Array(MechanizeCr::FormContent::Field)
|
||||||
getter checkboxes : Array(MechanizeCr::FormContent::CheckBox)
|
getter checkboxes : Array(MechanizeCr::FormContent::CheckBox)
|
||||||
getter enctype : String
|
getter enctype : String
|
||||||
|
property action : String
|
||||||
|
|
||||||
def initialize(node : Node | Myhtml::Node)
|
def initialize(node : Node | Myhtml::Node)
|
||||||
@enctype = node["enctype"] || "application/x-www-form-urlencoded"
|
@enctype = node["enctype"]? ? node["enctype"] : "application/x-www-form-urlencoded"
|
||||||
@node = node
|
@node = node
|
||||||
@fields = Array(MechanizeCr::FormContent::Field).new
|
@fields = Array(MechanizeCr::FormContent::Field).new
|
||||||
@checkboxes = Array(MechanizeCr::FormContent::CheckBox).new
|
@checkboxes = Array(MechanizeCr::FormContent::CheckBox).new
|
||||||
#@action = Mechanize::Util.html_unescape(node['action'])
|
#@action = Mechanize::Util.html_unescape(node['action'])
|
||||||
|
@action = node["action"]
|
||||||
#@method = (node['method'] || 'GET').upcase
|
#@method = (node['method'] || 'GET').upcase
|
||||||
#@name = node['name']
|
#@name = node['name']
|
||||||
#@clicked_buttons = []
|
#@clicked_buttons = []
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
# This is a fake node.
|
require "myhtml"
|
||||||
# Real node is represented by Myhtml::Node
|
|
||||||
|
|
||||||
|
# This is a fake node.
|
||||||
class Node < Hash(String,String)
|
class Node < Hash(String,String)
|
||||||
def css(str)
|
def css(str)
|
||||||
[] of Hash(String,String)
|
[] of Hash(String,String)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# This is a real Node.
|
||||||
|
struct Myhtml::Node
|
||||||
|
delegate :[], to: attributes
|
||||||
|
delegate :[]=, to: attributes
|
||||||
|
delegate :[]?, to: attributes
|
||||||
|
end
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
require "myhtml"
|
|
||||||
require "./file"
|
require "./file"
|
||||||
|
|
||||||
class MechanizeCr::Page < MechanizeCr::File
|
class MechanizeCr::Page < MechanizeCr::File
|
||||||
|
@ -15,4 +14,18 @@ class MechanizeCr::Page < MechanizeCr::File
|
||||||
def title
|
def title
|
||||||
title = parser.css("title").first.inner_text
|
title = parser.css("title").first.inner_text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def forms
|
||||||
|
#@forms ||= css("form").map do |html_form|
|
||||||
|
# form = Mechanize::Form.new(html_form, @mech, self)
|
||||||
|
# form.attributes["action"]# ||= @uri.to_s
|
||||||
|
# form
|
||||||
|
#end
|
||||||
|
|
||||||
|
forms = css("form").each do |html_form|
|
||||||
|
form = MechanizeCr::Form.new(html_form)
|
||||||
|
puts form.action# ||= @uri.to_s
|
||||||
|
form
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue