ronin-support-web
Description
ronin-support-web is a web support library for ronin-rb. ronin-support-web
provides many helper methods for parsing HTML/XML, fetching web pages, and
WebSockets.
Features
- Provides helper methods for parsing HTML/XML.
- Provides helper methods for working with WebSockets.
Examples
require 'ronin/support/web'
include Ronin::Support::Web
html_parse "<html>...</html>"
HTML
Parse an HTML string:
doc = html_parse("<html>\n <body>\n <p>Hello world</p>\n </body>\n</html>\n")
Parse a HTML file:
doc = html_open("index.html")
Searching an HTML document using XPath or CSS-path:
nodes = doc.search('//div/p')
nodes = doc.search('div p.class')
node = doc.at('#id')
Build a HTML document:
doc = html_build do
html {
head {
script(type: 'text/javascript', src: 'redirect.js')
}
}
end
puts doc.to_html
XML
Parse an XML response body:
xml_parse("<?xml version=\"1.0\"?>\n<users>\n <user>\n <name>admin</name>\n <password>0mni</password>\n <user>\n</users>\n")
Parse a XML file:
doc = html_open("data.xml")
Searching an XML document using XPath:
users = doc.search('//user')
admin = doc.at('//user[@name="admin"]')
Build a XML document:
doc = xml_build do
playlist {
mp3 {
file { text('02 THE WAIT.mp3') }
artist { text('Evil Nine') }
track { text('The Wait feat David Autokratz') }
duration { text('1000000000') }
}
}
end
puts doc.to_xml
Web Requests
Gets a URL and follows any redirects:
get 'https://example.com/'
Gets a URL and parses the HTML response:
get_html 'https://example.com/'
Gets a URL and parses the XML response:
get_xml 'https://example.com/sitemap.xml'
Gets a URL and parses the JSON response:
get_json 'https://example.com/api/endpoint.json'
POSTs to a URL and follows any redirects:
post 'https://example.com/form', form_data: {'foo' => 'bar'}
POSTs to a URL and parses the HTML response:
post_html 'https://example.com/form', form_data: {'foo' => 'bar'}
POSTs to a URL and parses the XML response:
post_xml 'https://example.com/form', form_data: {'foo' => 'bar'}
POSTs to a URL and parses the JSON response:
post_json 'https://example.com/api/endpoint.json', json: {foo: 'bar'}
WebSockets
Connecting to a WebSocket:
websocket = websocket_connect('ws://websocket-echo.com')
websocket.send_frame("foo bar")
websocket.recv_frame
websocket.send_frame("hello world")
websocket.recv
Starting a WebSocket server and receiving connections:
server = websocket_server('ws://localhost:1337/')
client = server.accept
client.send("hello")
client.recv
client = websocket_client('ws://localhost:1337/')
client.recv
client.send("good, how are you")
Requirements
Install
$ gem install ronin-support-web
Gemfile
gem 'ronin-support-web', '~> 0.1'
gemspec
gem.add_dependency 'ronin-support-web', '~> 0.1'
Development
- Fork It!
- Clone It!
cd ronin-support-web/
bundle install
git checkout -b my_feature
- Code It!
bundle exec rake spec
git push origin my_feature
License
ronin-support-web - A web support library for ronin-rb.
Copyright (c) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
ronin-support-web is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ronin-support-web is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ronin-support-web. If not, see https://www.gnu.org/licenses/.