add submit
parent
fbd99a854f
commit
813ba7248b
|
@ -60,6 +60,13 @@ class Mechanize
|
|||
@agent.request_headers = request_headers
|
||||
end
|
||||
|
||||
def submit(form)
|
||||
case form.method.upcase
|
||||
when "POST"
|
||||
post_form(form.action, form, request_headers)
|
||||
end
|
||||
end
|
||||
|
||||
def parse(uri, response, body)
|
||||
code = response.not_nil!.status_code
|
||||
MechanizeCr::Page.new(uri, response, body, code)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require "http/client"
|
||||
class MechanizeCr::File
|
||||
#property :body, :filename
|
||||
property :body, :code
|
||||
def initialize(uri : URI | Nil, response : ::HTTP::Client::Response | Nil, body : String , code : Int32 | Nil)
|
||||
property :body, :code, uri
|
||||
def initialize(uri : URI, response : ::HTTP::Client::Response | Nil, body : String , code : Int32 | Nil)
|
||||
@uri = uri
|
||||
@body = body
|
||||
@code = code
|
||||
|
|
|
@ -5,6 +5,7 @@ class MechanizeCr::Form
|
|||
getter fields : Array(MechanizeCr::FormContent::Field)
|
||||
getter checkboxes : Array(MechanizeCr::FormContent::CheckBox)
|
||||
getter enctype : String
|
||||
getter method : String
|
||||
property action : String
|
||||
|
||||
def initialize(node : Node | Myhtml::Node)
|
||||
|
@ -14,7 +15,7 @@ class MechanizeCr::Form
|
|||
@checkboxes = Array(MechanizeCr::FormContent::CheckBox).new
|
||||
#@action = Mechanize::Util.html_unescape(node['action'])
|
||||
@action = node["action"]
|
||||
#@method = (node['method'] || 'GET').upcase
|
||||
@method = (node["method"] || "GET").upcase
|
||||
#@name = node['name']
|
||||
#@clicked_buttons = []
|
||||
#@page = page
|
||||
|
|
|
@ -13,7 +13,7 @@ module MechanizeCr
|
|||
end
|
||||
|
||||
def fetch(uri, method = :get, headers = HTTP::Headers.new, params = Hash(String,String).new)
|
||||
uri = URI.parse(uri)
|
||||
uri = resolve(uri)
|
||||
set_request_headers(headers)
|
||||
uri, params = resolve_parameters(uri, method, params)
|
||||
response = http_request(uri, method, params)
|
||||
|
@ -72,6 +72,21 @@ module MechanizeCr
|
|||
header_cookies.not_nil!.add_request_headers(request_headers)
|
||||
end
|
||||
end
|
||||
|
||||
private def resolve(uri) : URI
|
||||
if uri.class == URI || uri.to_s.includes?("http")
|
||||
URI.parse(uri)
|
||||
else
|
||||
referer_uri = current_page.uri
|
||||
host = referer_uri.host
|
||||
scheme = referer_uri.scheme
|
||||
new_uri = URI.new(scheme: scheme, host: host, path: uri)
|
||||
end
|
||||
end
|
||||
|
||||
private def current_page
|
||||
@history.last
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue