ronin-web 0.3.0.pre2 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +11 -0
- data/.github/workflows/ruby.yml +31 -0
- data/.gitignore +13 -0
- data/.mailmap +1 -0
- data/.ruby-version +1 -0
- data/COPYING.txt +3 -3
- data/ChangeLog.md +115 -67
- data/Gemfile +42 -37
- data/README.md +159 -144
- data/Rakefile +16 -7
- data/bin/ronin-web +10 -18
- data/data/new/nokogiri.rb.erb +12 -0
- data/data/new/server.rb.erb +22 -0
- data/data/new/spider.rb.erb +26 -0
- data/data/new/webapp/.gitignore +15 -0
- data/data/new/webapp/.ruby-version.erb +1 -0
- data/data/new/webapp/Dockerfile.erb +11 -0
- data/data/new/webapp/Gemfile +6 -0
- data/data/new/webapp/app.rb.erb +15 -0
- data/data/new/webapp/config.ru +4 -0
- data/data/new/webapp/docker-compose.yml.erb +9 -0
- data/gemspec.yml +32 -17
- data/lib/ronin/web/cli/command.rb +36 -0
- data/lib/ronin/web/cli/commands/diff.rb +106 -0
- data/lib/ronin/web/cli/commands/html.rb +174 -0
- data/lib/ronin/web/cli/commands/irb.rb +56 -0
- data/lib/ronin/web/cli/commands/new/nokogiri.rb +85 -0
- data/lib/ronin/web/cli/commands/new/server.rb +96 -0
- data/lib/ronin/web/cli/commands/new/spider.rb +315 -0
- data/lib/ronin/web/cli/commands/new/webapp.rb +123 -0
- data/lib/ronin/web/cli/commands/new.rb +64 -0
- data/lib/ronin/web/cli/commands/reverse_proxy.rb +215 -0
- data/lib/ronin/web/cli/commands/server.rb +155 -0
- data/lib/ronin/web/cli/commands/spider.rb +822 -0
- data/lib/ronin/web/cli/ruby_shell.rb +50 -0
- data/lib/ronin/web/cli.rb +44 -0
- data/lib/ronin/web/html.rb +85 -0
- data/lib/ronin/web/mechanize.rb +79 -0
- data/lib/ronin/web/root.rb +27 -0
- data/lib/ronin/web/version.rb +7 -10
- data/lib/ronin/web/xml.rb +85 -0
- data/lib/ronin/web.rb +372 -13
- data/man/ronin-web-diff.1 +41 -0
- data/man/ronin-web-diff.1.md +30 -0
- data/man/ronin-web-html.1 +89 -0
- data/man/ronin-web-html.1.md +66 -0
- data/man/ronin-web-irb.1 +31 -0
- data/man/ronin-web-irb.1.md +22 -0
- data/man/ronin-web-new-nokogiri.1 +41 -0
- data/man/ronin-web-new-nokogiri.1.md +30 -0
- data/man/ronin-web-new-server.1 +45 -0
- data/man/ronin-web-new-server.1.md +33 -0
- data/man/ronin-web-new-spider.1 +173 -0
- data/man/ronin-web-new-spider.1.md +129 -0
- data/man/ronin-web-new-webapp.1 +53 -0
- data/man/ronin-web-new-webapp.1.md +39 -0
- data/man/ronin-web-new.1 +59 -0
- data/man/ronin-web-new.1.md +44 -0
- data/man/ronin-web-reverse-proxy.1 +63 -0
- data/man/ronin-web-reverse-proxy.1.md +47 -0
- data/man/ronin-web-server.1 +59 -0
- data/man/ronin-web-server.1.md +43 -0
- data/man/ronin-web-spider.1 +225 -0
- data/man/ronin-web-spider.1.md +168 -0
- data/man/ronin-web.1 +41 -0
- data/man/ronin-web.1.md +30 -0
- data/ronin-web.gemspec +57 -11
- data/spec/cli/ruby_shell_spec.rb +14 -0
- data/spec/html_spec.rb +43 -0
- data/spec/mechanize_spec.rb +72 -0
- data/spec/spec_helper.rb +5 -3
- data/spec/web_spec.rb +97 -0
- data/spec/xml_spec.rb +42 -0
- metadata +237 -217
- data/.gemtest +0 -0
- data/lib/ronin/network/mixins/web.rb +0 -256
- data/lib/ronin/web/extensions/nokogiri/xml/attr.rb +0 -47
- data/lib/ronin/web/extensions/nokogiri/xml/document.rb +0 -48
- data/lib/ronin/web/extensions/nokogiri/xml/element.rb +0 -57
- data/lib/ronin/web/extensions/nokogiri/xml/node.rb +0 -86
- data/lib/ronin/web/extensions/nokogiri/xml/text.rb +0 -47
- data/lib/ronin/web/extensions/nokogiri/xml.rb +0 -27
- data/lib/ronin/web/extensions/nokogiri.rb +0 -23
- data/lib/ronin/web/extensions.rb +0 -23
- data/lib/ronin/web/middleware/base.rb +0 -144
- data/lib/ronin/web/middleware/directories.rb +0 -179
- data/lib/ronin/web/middleware/files.rb +0 -144
- data/lib/ronin/web/middleware/filters/campaign_filter.rb +0 -77
- data/lib/ronin/web/middleware/filters/ip_filter.rb +0 -73
- data/lib/ronin/web/middleware/filters/path_filter.rb +0 -73
- data/lib/ronin/web/middleware/filters/referer_filter.rb +0 -71
- data/lib/ronin/web/middleware/filters/user_agent_filter.rb +0 -71
- data/lib/ronin/web/middleware/filters/vhost_filter.rb +0 -71
- data/lib/ronin/web/middleware/filters.rb +0 -28
- data/lib/ronin/web/middleware/helpers.rb +0 -145
- data/lib/ronin/web/middleware/proxy.rb +0 -265
- data/lib/ronin/web/middleware/proxy_request.rb +0 -262
- data/lib/ronin/web/middleware/request.rb +0 -79
- data/lib/ronin/web/middleware/response.rb +0 -33
- data/lib/ronin/web/middleware/router.rb +0 -167
- data/lib/ronin/web/middleware/rule.rb +0 -103
- data/lib/ronin/web/middleware.rb +0 -27
- data/lib/ronin/web/proxy/app.rb +0 -32
- data/lib/ronin/web/proxy/base.rb +0 -46
- data/lib/ronin/web/proxy/web.rb +0 -46
- data/lib/ronin/web/proxy.rb +0 -25
- data/lib/ronin/web/server/app.rb +0 -32
- data/lib/ronin/web/server/base.rb +0 -461
- data/lib/ronin/web/server/web.rb +0 -66
- data/lib/ronin/web/server.rb +0 -25
- data/lib/ronin/web/spider.rb +0 -115
- data/lib/ronin/web/web.rb +0 -573
- data/spec/helpers/output.rb +0 -3
- data/spec/web/extensions/nokogiri_spec.rb +0 -38
- data/spec/web/helpers/rack_app.rb +0 -31
- data/spec/web/helpers/root/test1/index.html +0 -1
- data/spec/web/helpers/root/test1/test1.txt +0 -1
- data/spec/web/helpers/root/test1.txt +0 -1
- data/spec/web/helpers/root/test2/test2.txt +0 -1
- data/spec/web/helpers/root/test2.txt +0 -1
- data/spec/web/helpers/root/test3/test3.txt +0 -1
- data/spec/web/helpers/root/test3.txt +0 -1
- data/spec/web/helpers/root.rb +0 -15
- data/spec/web/middleware/directories_spec.rb +0 -86
- data/spec/web/middleware/files_spec.rb +0 -57
- data/spec/web/middleware/filters/campaign_filter_spec.rb +0 -30
- data/spec/web/middleware/filters/ip_filter_spec.rb +0 -25
- data/spec/web/middleware/filters/path_filter_spec.rb +0 -29
- data/spec/web/middleware/filters/referer_filter_spec.rb +0 -25
- data/spec/web/middleware/filters/user_agent_filter_spec.rb +0 -25
- data/spec/web/middleware/filters/vhost_filter_spec.rb +0 -23
- data/spec/web/middleware/proxy_spec.rb +0 -67
- data/spec/web/middleware/response_spec.rb +0 -20
- data/spec/web/middleware/router_spec.rb +0 -65
- data/spec/web/middleware/rule_spec.rb +0 -37
- data/spec/web/proxy/base_spec.rb +0 -8
- data/spec/web/server/base_spec.rb +0 -77
- data/spec/web/server/classes/public1/static1.txt +0 -1
- data/spec/web/server/classes/public2/static2.txt +0 -1
- data/spec/web/server/classes/sub_app.rb +0 -13
- data/spec/web/server/classes/test_app.rb +0 -20
- data/spec/web/web_spec.rb +0 -157
data/lib/ronin/web/spider.rb
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
-
# scraping and spidering functionality.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This file is part of Ronin Web.
|
8
|
-
#
|
9
|
-
# Ronin is free software: you can redistribute it and/or modify
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
12
|
-
# (at your option) any later version.
|
13
|
-
#
|
14
|
-
# Ronin is distributed in the hope that it will be useful,
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
-
# GNU General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
-
#
|
22
|
-
|
23
|
-
require 'ronin/web/web'
|
24
|
-
require 'ronin/ui/output/helpers'
|
25
|
-
|
26
|
-
require 'spidr/agent'
|
27
|
-
|
28
|
-
module Ronin
|
29
|
-
module Web
|
30
|
-
#
|
31
|
-
# Extends [Spidr::Agent](http://rubydoc.info/gems/spidr/Agent) with
|
32
|
-
# [Ronin::UI::Output::Helpers](http://rubydoc.info/gems/ronin/Ronin/UI/Output/Helpers).
|
33
|
-
#
|
34
|
-
class Spider < Spidr::Agent
|
35
|
-
|
36
|
-
include UI::Output::Helpers
|
37
|
-
|
38
|
-
#
|
39
|
-
# Creates a new Spider object.
|
40
|
-
#
|
41
|
-
# @param [Hash] options
|
42
|
-
# Additional options.
|
43
|
-
#
|
44
|
-
# @option options [Hash] :proxy (Web.proxy)
|
45
|
-
# The proxy to use while spidering.
|
46
|
-
#
|
47
|
-
# @option options [String] :user_agent (Web.user_agent)
|
48
|
-
# The User-Agent string to send.
|
49
|
-
#
|
50
|
-
# @option options [String] :referer
|
51
|
-
# The referer URL to send.
|
52
|
-
#
|
53
|
-
# @option options [Integer] :delay (0)
|
54
|
-
# Duration in seconds to pause between spidering each link.
|
55
|
-
#
|
56
|
-
# @option options [Array] :schemes (['http', 'https'])
|
57
|
-
# The list of acceptable URI schemes to visit.
|
58
|
-
# The `https` scheme will be ignored if `net/https` cannot be
|
59
|
-
# loaded.
|
60
|
-
#
|
61
|
-
# @option options [String] :host
|
62
|
-
# The host-name to visit.
|
63
|
-
#
|
64
|
-
# @option options [Array<String, Regexp, Proc>] :hosts
|
65
|
-
# The patterns which match the host-names to visit.
|
66
|
-
#
|
67
|
-
# @option options [Array<String, Regexp, Proc>] :ignore_hosts
|
68
|
-
# The patterns which match the host-names to not visit.
|
69
|
-
#
|
70
|
-
# @option options [Array<Integer, Regexp, Proc>] :ports
|
71
|
-
# The patterns which match the ports to visit.
|
72
|
-
#
|
73
|
-
# @option options [Array<Integer, Regexp, Proc>] :ignore_ports
|
74
|
-
# The patterns which match the ports to not visit.
|
75
|
-
#
|
76
|
-
# @option options [Array<String, Regexp, Proc>] :links
|
77
|
-
# The patterns which match the links to visit.
|
78
|
-
#
|
79
|
-
# @option options [Array<String, Regexp, Proc>] :ignore_links
|
80
|
-
# The patterns which match the links to not visit.
|
81
|
-
#
|
82
|
-
# @option options [Array<String, Regexp, Proc>] :exts
|
83
|
-
# The patterns which match the URI path extensions to visit.
|
84
|
-
#
|
85
|
-
# @option options [Array<String, Regexp, Proc>] :ignore_exts
|
86
|
-
# The patterns which match the URI path extensions to not visit.
|
87
|
-
#
|
88
|
-
# @yield [spider]
|
89
|
-
# If a block is given, it will be passed the newly created spider.
|
90
|
-
#
|
91
|
-
# @yieldparam [Spider] spider
|
92
|
-
# The newly created spider.
|
93
|
-
#
|
94
|
-
# @see http://spidr.rubyforge.org/docs/classes/Spidr/Agent.html
|
95
|
-
#
|
96
|
-
# @api public
|
97
|
-
#
|
98
|
-
def initialize(options={})
|
99
|
-
options = {
|
100
|
-
:proxy => Web.proxy,
|
101
|
-
:user_agent => Web.user_agent
|
102
|
-
}.merge(options)
|
103
|
-
|
104
|
-
super(options)
|
105
|
-
|
106
|
-
every_url do |url|
|
107
|
-
print_info("Spidering #{url}")
|
108
|
-
end
|
109
|
-
|
110
|
-
yield self if block_given?
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
data/lib/ronin/web/web.rb
DELETED
@@ -1,573 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Ronin Web - A Ruby library for Ronin that provides support for web
|
3
|
-
# scraping and spidering functionality.
|
4
|
-
#
|
5
|
-
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
-
#
|
7
|
-
# This file is part of Ronin Web.
|
8
|
-
#
|
9
|
-
# Ronin is free software: you can redistribute it and/or modify
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
12
|
-
# (at your option) any later version.
|
13
|
-
#
|
14
|
-
# Ronin is distributed in the hope that it will be useful,
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
-
# GNU General Public License for more details.
|
18
|
-
#
|
19
|
-
# You should have received a copy of the GNU General Public License
|
20
|
-
# along with Ronin. If not, see <http://www.gnu.org/licenses/>.
|
21
|
-
#
|
22
|
-
|
23
|
-
require 'ronin/network/http/proxy'
|
24
|
-
require 'ronin/network/http/http'
|
25
|
-
|
26
|
-
require 'uri/http'
|
27
|
-
require 'nokogiri'
|
28
|
-
require 'mechanize'
|
29
|
-
require 'open-uri'
|
30
|
-
|
31
|
-
module Ronin
|
32
|
-
module Web
|
33
|
-
#
|
34
|
-
# Parses the body of a document into a HTML document object.
|
35
|
-
#
|
36
|
-
# @param [String, IO] body
|
37
|
-
# The body of the document to parse.
|
38
|
-
#
|
39
|
-
# @yield [doc]
|
40
|
-
# If a block is given, it will be passed the newly created document
|
41
|
-
# object.
|
42
|
-
#
|
43
|
-
# @yieldparam [Nokogiri::HTML::Document] doc
|
44
|
-
# The new HTML document object.
|
45
|
-
#
|
46
|
-
# @return [Nokogiri::HTML::Document]
|
47
|
-
# The new HTML document object.
|
48
|
-
#
|
49
|
-
# @see http://rubydoc.info/gems/nokogiri/Nokogiri/HTML/Document
|
50
|
-
#
|
51
|
-
# @api public
|
52
|
-
#
|
53
|
-
def Web.html(body)
|
54
|
-
doc = Nokogiri::HTML(body)
|
55
|
-
|
56
|
-
yield doc if block_given?
|
57
|
-
return doc
|
58
|
-
end
|
59
|
-
|
60
|
-
#
|
61
|
-
# Creates a new Nokogiri::HTML::Builder.
|
62
|
-
#
|
63
|
-
# @yield []
|
64
|
-
# The block that will be used to construct the HTML document.
|
65
|
-
#
|
66
|
-
# @return [Nokogiri::HTML::Builder]
|
67
|
-
# The new HTML builder object.
|
68
|
-
#
|
69
|
-
# @example
|
70
|
-
# Web.build_html do
|
71
|
-
# html {
|
72
|
-
# body {
|
73
|
-
# div(:style => 'display:none;') {
|
74
|
-
# object(:classid => 'blabla')
|
75
|
-
# }
|
76
|
-
# }
|
77
|
-
# }
|
78
|
-
# end
|
79
|
-
#
|
80
|
-
# @see http://rubydoc.info/gems/nokogiri/Nokogiri/HTML/Builder
|
81
|
-
#
|
82
|
-
# @api public
|
83
|
-
#
|
84
|
-
def Web.build_html(&block)
|
85
|
-
Nokogiri::HTML::Builder.new(&block)
|
86
|
-
end
|
87
|
-
|
88
|
-
#
|
89
|
-
# Parses the body of a document into a XML document object.
|
90
|
-
#
|
91
|
-
# @param [String, IO] body
|
92
|
-
# The body of the document to parse.
|
93
|
-
#
|
94
|
-
# @yield [doc]
|
95
|
-
# If a block is given, it will be passed the newly created document
|
96
|
-
# object.
|
97
|
-
#
|
98
|
-
# @yieldparam [Nokogiri::XML::Document] doc
|
99
|
-
# The new XML document object.
|
100
|
-
#
|
101
|
-
# @return [Nokogiri::XML::Document]
|
102
|
-
# The new XML document object.
|
103
|
-
#
|
104
|
-
# @see http://rubydoc.info/gems/nokogiri/Nokogiri/XML/Document
|
105
|
-
#
|
106
|
-
# @api public
|
107
|
-
#
|
108
|
-
def Web.xml(body)
|
109
|
-
doc = Nokogiri::XML(body)
|
110
|
-
|
111
|
-
yield doc if block_given?
|
112
|
-
return doc
|
113
|
-
end
|
114
|
-
|
115
|
-
#
|
116
|
-
# Creates a new Nokogiri::XML::Builder.
|
117
|
-
#
|
118
|
-
# @yield []
|
119
|
-
# The block that will be used to construct the XML document.
|
120
|
-
#
|
121
|
-
# @return [Nokogiri::XML::Builder]
|
122
|
-
# The new XML builder object.
|
123
|
-
#
|
124
|
-
# @example
|
125
|
-
# Web.build_xml do
|
126
|
-
# post(:id => 2) {
|
127
|
-
# title { text('some example') }
|
128
|
-
# body { text('this is one contrived example.') }
|
129
|
-
# }
|
130
|
-
# end
|
131
|
-
#
|
132
|
-
# @see http://rubydoc.info/gems/nokogiri/Nokogiri/XML/Builder
|
133
|
-
#
|
134
|
-
# @api public
|
135
|
-
#
|
136
|
-
def Web.build_xml(&block)
|
137
|
-
Nokogiri::XML::Builder.new(&block)
|
138
|
-
end
|
139
|
-
|
140
|
-
#
|
141
|
-
# Proxy information for {Web} to use.
|
142
|
-
#
|
143
|
-
# @return [Network::HTTP::Proxy]
|
144
|
-
# The Ronin Web proxy information.
|
145
|
-
#
|
146
|
-
# @see http://rubydoc.info/gems/ronin-support/Ronin/Network/HTTP#proxy-class_method
|
147
|
-
#
|
148
|
-
# @api public
|
149
|
-
#
|
150
|
-
def Web.proxy
|
151
|
-
(@proxy ||= nil) || Network::HTTP.proxy
|
152
|
-
end
|
153
|
-
|
154
|
-
#
|
155
|
-
# Sets the proxy used by {Web}.
|
156
|
-
#
|
157
|
-
# @param [Network::HTTP::Proxy, URI::HTTP, Hash, String] new_proxy
|
158
|
-
# The new proxy information to use.
|
159
|
-
#
|
160
|
-
# @return [Network::HTTP::Proxy]
|
161
|
-
# The new proxy.
|
162
|
-
#
|
163
|
-
# @since 0.3.0
|
164
|
-
#
|
165
|
-
# @api public
|
166
|
-
#
|
167
|
-
def Web.proxy=(new_proxy)
|
168
|
-
@proxy = Network::HTTP::Proxy.create(new_proxy)
|
169
|
-
end
|
170
|
-
|
171
|
-
#
|
172
|
-
# @return [Array]
|
173
|
-
# The supported Web User-Agent Aliases.
|
174
|
-
#
|
175
|
-
# @see http://rubydoc.info/gems/mechanize/Mechanize#AGENT_ALIASES-constant
|
176
|
-
#
|
177
|
-
# @api public
|
178
|
-
#
|
179
|
-
def Web.user_agent_aliases
|
180
|
-
Mechanize::AGENT_ALIASES
|
181
|
-
end
|
182
|
-
|
183
|
-
#
|
184
|
-
# The User-Agent string used by {Web}.
|
185
|
-
#
|
186
|
-
# @return [String, nil]
|
187
|
-
# The Ronin Web User-Agent
|
188
|
-
#
|
189
|
-
# @see http://rubydoc.info/gems/ronin-support/Ronin/Network/HTTP#user_agent-class_method
|
190
|
-
#
|
191
|
-
# @api public
|
192
|
-
#
|
193
|
-
def Web.user_agent
|
194
|
-
(@user_agent ||= nil) || Network::HTTP.user_agent
|
195
|
-
end
|
196
|
-
|
197
|
-
#
|
198
|
-
# Sets the User-Agent string used by {Web}.
|
199
|
-
#
|
200
|
-
# @param [String] new_agent
|
201
|
-
# The User-Agent string to use.
|
202
|
-
#
|
203
|
-
# @return [String]
|
204
|
-
# The new User-Agent string.
|
205
|
-
#
|
206
|
-
# @api public
|
207
|
-
#
|
208
|
-
def Web.user_agent=(new_agent)
|
209
|
-
@user_agent = new_agent
|
210
|
-
end
|
211
|
-
|
212
|
-
#
|
213
|
-
# Sets the Ronin Web User-Agent.
|
214
|
-
#
|
215
|
-
# @param [String] name
|
216
|
-
# The User-Agent alias to use.
|
217
|
-
#
|
218
|
-
# @return [String]
|
219
|
-
# The new User-Agent string.
|
220
|
-
#
|
221
|
-
# @see user_agent_aliases
|
222
|
-
#
|
223
|
-
# @api public
|
224
|
-
#
|
225
|
-
def Web.user_agent_alias=(name)
|
226
|
-
@user_agent = Web.user_agent_aliases[name.to_s]
|
227
|
-
end
|
228
|
-
|
229
|
-
#
|
230
|
-
# Opens a URL as a temporary file.
|
231
|
-
#
|
232
|
-
# @param [Hash] options
|
233
|
-
# Additional options.
|
234
|
-
#
|
235
|
-
# @option options [String] :user_agent_alias
|
236
|
-
# The User-Agent Alias to use.
|
237
|
-
#
|
238
|
-
# @option options [String] :user_agent
|
239
|
-
# The User-Agent string to use.
|
240
|
-
#
|
241
|
-
# @option options [Network::HTTP::Proxy, Hash, String] :proxy
|
242
|
-
# (Web.proxy)
|
243
|
-
# Proxy information.
|
244
|
-
#
|
245
|
-
# @option options [String] :user
|
246
|
-
# The HTTP Basic Authentication user name.
|
247
|
-
#
|
248
|
-
# @option options [String] :password
|
249
|
-
# The HTTP Basic Authentication password.
|
250
|
-
#
|
251
|
-
# @option options [Proc] :content_length_proc
|
252
|
-
# A callback which will be passed the content-length of the HTTP
|
253
|
-
# response.
|
254
|
-
#
|
255
|
-
# @option options [Proc] :progress_proc
|
256
|
-
# A callback which will be passed the size of each fragment, once
|
257
|
-
# received from the server.
|
258
|
-
#
|
259
|
-
# @return [File]
|
260
|
-
# The contents of the URL.
|
261
|
-
#
|
262
|
-
# @example Open a given URL.
|
263
|
-
# Web.open('http://rubyflow.com/')
|
264
|
-
#
|
265
|
-
# @example Open a given URL, using a custom User-Agent alias.
|
266
|
-
# Web.open('http://tenderlovemaking.com/',
|
267
|
-
# :user_agent_alias => 'Linux Mozilla')
|
268
|
-
#
|
269
|
-
# @example Open a given URL, using a custom User-Agent string.
|
270
|
-
# Web.open('http://www.wired.com/', :user_agent => 'the future')
|
271
|
-
#
|
272
|
-
# @see http://rubydoc.info/stdlib/open-uri/frames
|
273
|
-
#
|
274
|
-
# @api public
|
275
|
-
#
|
276
|
-
def Web.open(url,options={})
|
277
|
-
user_agent_alias = options.delete(:user_agent_alias)
|
278
|
-
proxy = Network::HTTP::Proxy.create(
|
279
|
-
options.delete(:proxy) || Web.proxy
|
280
|
-
)
|
281
|
-
user = options.delete(:user)
|
282
|
-
password = options.delete(:password)
|
283
|
-
content_length_proc = options.delete(:content_length_proc)
|
284
|
-
progress_proc = options.delete(:progress_proc)
|
285
|
-
|
286
|
-
headers = Network::HTTP.headers(options)
|
287
|
-
|
288
|
-
if user_agent_alias
|
289
|
-
headers['User-Agent'] = Web.user_agent_aliases[user_agent_alias]
|
290
|
-
end
|
291
|
-
|
292
|
-
if proxy[:host]
|
293
|
-
headers[:proxy] = proxy.url
|
294
|
-
end
|
295
|
-
|
296
|
-
if user
|
297
|
-
headers[:http_basic_authentication] = [user, password]
|
298
|
-
end
|
299
|
-
|
300
|
-
if content_length_proc
|
301
|
-
headers[:content_length_proc] = content_length_proc
|
302
|
-
end
|
303
|
-
|
304
|
-
if progress_proc
|
305
|
-
headers[:progress_proc] = progress_proc
|
306
|
-
end
|
307
|
-
|
308
|
-
return Kernel.open(url,headers)
|
309
|
-
end
|
310
|
-
|
311
|
-
#
|
312
|
-
# Creates a new Mechanize Agent.
|
313
|
-
#
|
314
|
-
# @param [Hash] options
|
315
|
-
# Additional options.
|
316
|
-
#
|
317
|
-
# @option options [String] :user_agent_alias
|
318
|
-
# The User-Agent Alias to use.
|
319
|
-
#
|
320
|
-
# @option options [String] :user_agent
|
321
|
-
# The User-Agent string to use.
|
322
|
-
#
|
323
|
-
# @option options [Network::HTTP::Proxy, Hash, String] :proxy
|
324
|
-
# (Web.proxy)
|
325
|
-
# Proxy information.
|
326
|
-
#
|
327
|
-
# @yield [agent]
|
328
|
-
# If a block is given, it will be passed the newly created Mechanize
|
329
|
-
# agent.
|
330
|
-
#
|
331
|
-
# @yieldparam [Mechanize] agent
|
332
|
-
# The new Mechanize agent.
|
333
|
-
#
|
334
|
-
# @return [Mechanize]
|
335
|
-
# The new Mechanize agent.
|
336
|
-
#
|
337
|
-
# @example Create a new agent.
|
338
|
-
# Web.agent
|
339
|
-
#
|
340
|
-
# @example Create a new agent, with a custom User-Agent alias.
|
341
|
-
# Web.agent(:user_agent_alias => 'Linux Mozilla')
|
342
|
-
#
|
343
|
-
# @example Create a new agent, with a custom User-Agent string.
|
344
|
-
# Web.agent(:user_agent => 'wooden pants')
|
345
|
-
#
|
346
|
-
# @see http://rubydoc.info/gems/mechanize/Mechanize
|
347
|
-
#
|
348
|
-
# @api public
|
349
|
-
#
|
350
|
-
def Web.agent(options={})
|
351
|
-
agent = Mechanize.new
|
352
|
-
|
353
|
-
if options[:user_agent_alias]
|
354
|
-
agent.user_agent_alias = options[:user_agent_alias]
|
355
|
-
elsif options[:user_agent]
|
356
|
-
agent.user_agent = options[:user_agent]
|
357
|
-
elsif Web.user_agent
|
358
|
-
agent.user_agent = Web.user_agent
|
359
|
-
end
|
360
|
-
|
361
|
-
proxy = Network::HTTP::Proxy.new(options[:proxy] || Web.proxy)
|
362
|
-
|
363
|
-
if proxy[:host]
|
364
|
-
agent.set_proxy(
|
365
|
-
proxy[:host],
|
366
|
-
proxy[:port],
|
367
|
-
proxy[:user],
|
368
|
-
proxy[:password]
|
369
|
-
)
|
370
|
-
end
|
371
|
-
|
372
|
-
yield agent if block_given?
|
373
|
-
return agent
|
374
|
-
end
|
375
|
-
|
376
|
-
#
|
377
|
-
# Creates a Mechanize Page for the contents at a given URL.
|
378
|
-
#
|
379
|
-
# @param [URI::Generic, String] url
|
380
|
-
# The URL to request.
|
381
|
-
#
|
382
|
-
# @param [Hash] options
|
383
|
-
# Additional options.
|
384
|
-
#
|
385
|
-
# @option options [String] :user_agent_alias
|
386
|
-
# The User-Agent Alias to use.
|
387
|
-
#
|
388
|
-
# @option options [String] :user_agent
|
389
|
-
# The User-Agent string to use.
|
390
|
-
#
|
391
|
-
# @option options [Network::HTTP::Proxy, Hash] :proxy (Web.proxy)
|
392
|
-
# Proxy information.
|
393
|
-
#
|
394
|
-
# @yield [page]
|
395
|
-
# If a block is given, it will be passed the page for the requested
|
396
|
-
# URL.
|
397
|
-
#
|
398
|
-
# @yieldparam [Mechanize::Page] page
|
399
|
-
# The requested page.
|
400
|
-
#
|
401
|
-
# @return [Mechanize::Page]
|
402
|
-
# The requested page.
|
403
|
-
#
|
404
|
-
# @example
|
405
|
-
# Web.get('http://www.rubyinside.com')
|
406
|
-
# # => Mechanize::Page
|
407
|
-
#
|
408
|
-
# @example
|
409
|
-
# Web.get('http://www.rubyinside.com') do |page|
|
410
|
-
# page.search('div.post/h2/a').each do |title|
|
411
|
-
# puts title.inner_text
|
412
|
-
# end
|
413
|
-
# end
|
414
|
-
#
|
415
|
-
# @see http://rubydoc.info/gems/mechanize/Mechanize/Page
|
416
|
-
#
|
417
|
-
# @api public
|
418
|
-
#
|
419
|
-
def Web.get(url,options={})
|
420
|
-
page = Web.agent(options).get(url)
|
421
|
-
|
422
|
-
yield page if block_given?
|
423
|
-
return page
|
424
|
-
end
|
425
|
-
|
426
|
-
#
|
427
|
-
# Requests the body of the Mechanize Page created from the response
|
428
|
-
# of the given URL.
|
429
|
-
#
|
430
|
-
# @param [URI::Generic, String] url
|
431
|
-
# The URL to request.
|
432
|
-
#
|
433
|
-
# @param [Hash] options
|
434
|
-
# Additional options.
|
435
|
-
#
|
436
|
-
# @option options [String] :user_agent_alias
|
437
|
-
# The User-Agent Alias to use.
|
438
|
-
#
|
439
|
-
# @option options [String] :user_agent
|
440
|
-
# The User-Agent string to use.
|
441
|
-
#
|
442
|
-
# @option options [Network::HTTP::Proxy, Hash] :proxy (Web.proxy)
|
443
|
-
# Proxy information.
|
444
|
-
#
|
445
|
-
# @yield [body]
|
446
|
-
# If a block is given, it will be passed the body of the page.
|
447
|
-
#
|
448
|
-
# @yieldparam [String] body
|
449
|
-
# The requested body of the page.
|
450
|
-
#
|
451
|
-
# @return [String]
|
452
|
-
# The requested body of the page.
|
453
|
-
#
|
454
|
-
# @example
|
455
|
-
# Web.get_body('http://www.rubyinside.com') # => String
|
456
|
-
#
|
457
|
-
# @example
|
458
|
-
# Web.get_body('http://www.rubyinside.com') do |body|
|
459
|
-
# puts body
|
460
|
-
# end
|
461
|
-
#
|
462
|
-
# @see get
|
463
|
-
#
|
464
|
-
# @api public
|
465
|
-
#
|
466
|
-
def Web.get_body(url,options={})
|
467
|
-
body = Web.get(url,options).body
|
468
|
-
|
469
|
-
yield body if block_given?
|
470
|
-
return body
|
471
|
-
end
|
472
|
-
|
473
|
-
#
|
474
|
-
# Posts to a given URL and creates a Mechanize Page from the response.
|
475
|
-
#
|
476
|
-
# @param [URI::Generic, String] url
|
477
|
-
# The URL to request.
|
478
|
-
#
|
479
|
-
# @param [Hash] options
|
480
|
-
# Additional options.
|
481
|
-
#
|
482
|
-
# @option options [Hash] :query
|
483
|
-
# Additional query parameters to post with.
|
484
|
-
#
|
485
|
-
# @option options [String] :user_agent_alias
|
486
|
-
# The User-Agent Alia to use.
|
487
|
-
#
|
488
|
-
# @option options [String] :user_agent
|
489
|
-
# The User-Agent string to use.
|
490
|
-
#
|
491
|
-
# @option options [Network::HTTP::Proxy, Hash] :proxy (Web.proxy)
|
492
|
-
# Proxy information.
|
493
|
-
#
|
494
|
-
# @yield [page]
|
495
|
-
# If a block is given, it will be passed the page for the requested
|
496
|
-
# URL.
|
497
|
-
#
|
498
|
-
# @yieldparam [Mechanize::Page] page
|
499
|
-
# The requested page.
|
500
|
-
#
|
501
|
-
# @return [Mechanize::Page]
|
502
|
-
# The requested page.
|
503
|
-
#
|
504
|
-
# @example
|
505
|
-
# Web.post('http://www.rubyinside.com')
|
506
|
-
# # => Mechanize::Page
|
507
|
-
#
|
508
|
-
# @see http://rubydoc.info/gems/mechanize/Mechanize/Page
|
509
|
-
#
|
510
|
-
# @api public
|
511
|
-
#
|
512
|
-
def Web.post(url,options={})
|
513
|
-
query = {}
|
514
|
-
query.merge!(options[:query]) if options[:query]
|
515
|
-
|
516
|
-
page = Web.agent(options).post(url,query)
|
517
|
-
|
518
|
-
yield page if block_given?
|
519
|
-
return page
|
520
|
-
end
|
521
|
-
|
522
|
-
#
|
523
|
-
# Posts to a given URL and returns the body of the Mechanize Page
|
524
|
-
# created from the response.
|
525
|
-
#
|
526
|
-
# @param [URI::Generic, String] url
|
527
|
-
# The URL to request.
|
528
|
-
#
|
529
|
-
# @param [Hash] options
|
530
|
-
# Additional options.
|
531
|
-
#
|
532
|
-
# @option options [Hash] :query
|
533
|
-
# Additional query parameters to post with.
|
534
|
-
#
|
535
|
-
# @option options [String] :user_agent_alias
|
536
|
-
# The User-Agent Alias to use.
|
537
|
-
#
|
538
|
-
# @option options [String] :user_agent
|
539
|
-
# The User-Agent string to use.
|
540
|
-
#
|
541
|
-
# @option options [Network::HTTP::Proxy, Hash] :proxy (Web.proxy)
|
542
|
-
# Proxy information.
|
543
|
-
#
|
544
|
-
# @yield [body]
|
545
|
-
# If a block is given, it will be passed the body of the page.
|
546
|
-
#
|
547
|
-
# @yieldparam [Mechanize::Page] page
|
548
|
-
# The body of the requested page.
|
549
|
-
#
|
550
|
-
# @return [Mechanize::Page]
|
551
|
-
# The body of the requested page.
|
552
|
-
#
|
553
|
-
# @example
|
554
|
-
# Web.post_body('http://www.rubyinside.com')
|
555
|
-
# # => String
|
556
|
-
#
|
557
|
-
# @example
|
558
|
-
# Web.post_body('http://www.rubyinside.com') do |body|
|
559
|
-
# puts body
|
560
|
-
# end
|
561
|
-
#
|
562
|
-
# @see post
|
563
|
-
#
|
564
|
-
# @api public
|
565
|
-
#
|
566
|
-
def Web.post_body(url,options={})
|
567
|
-
body = Web.post(url,options).body
|
568
|
-
|
569
|
-
yield body if block_given?
|
570
|
-
return body
|
571
|
-
end
|
572
|
-
end
|
573
|
-
end
|
data/spec/helpers/output.rb
DELETED