This commit is contained in:
Kanezoh 2021-05-22 17:18:18 +09:00
parent 1dd6e72025
commit 62a178f0da
3 changed files with 9 additions and 7 deletions

10
main.cr
View File

@ -2,11 +2,11 @@ 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://google.com/", params: params) #page = agent.get("http://example.com/", params: params)
#query = {"foo" => "foo_value", "bar" => "bar_value"} query = {"foo" => "foo_value", "bar" => "bar_value"}
#page = agent.post("http//example.com/", query: query) 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

View File

@ -45,7 +45,7 @@ class Mechanize
headers.merge!(content_headers) headers.merge!(content_headers)
# fetch the page # fetch the page
page = @agent.fetch uri, :post, headers, [request_data]#, cur_page page = @agent.fetch(uri, :post, headers: headers, params: {"value" => request_data })#, cur_page
#add_to_history(page) #add_to_history(page)
page page
end end

View File

@ -30,7 +30,7 @@ module MechanizeCr
when :get when :get
::HTTP::Client.get(uri, headers: request_headers) ::HTTP::Client.get(uri, headers: request_headers)
when :post when :post
#client.post(path) ::HTTP::Client.post(uri, headers: request_headers, form: params.not_nil!.fetch("value", ""))
end end
end end
end end
@ -47,6 +47,8 @@ module MechanizeCr
query = URI::Params.encode(params) query = URI::Params.encode(params)
uri.query = query uri.query = query
return uri, nil return uri, nil
when :post
return uri, params
else else
return uri, params return uri, params
end end