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