Class: Ronin::Web::Mechanize

Inherits:
Mechanize
  • Object
show all
Defined in:
lib/ronin/web/mechanize.rb

Overview

Convenience class based on Mechanize.

Instance Method Summary collapse

Constructor Details

#initialize(proxy: Support::Network::HTTP.proxy, user_agent: Support::Network::HTTP.user_agent) {|agent| ... } ⇒ Mechanize

Creates a new Mechanize Agent.

The User-Agent string to use.

Parameters:

  • proxy (Network::HTTP::Proxy, Hash, String) (defaults to: Support::Network::HTTP.proxy)

    Proxy information.

  • user_agent (String, :random, :chrome, :chrome_linux, :chrome_macos, :chrome_windows, :chrome_iphone, :chrome_ipad, :chrome_android, :firefox, :firefox_linux, :firefox_macos, :firefox_windows, :firefox_iphone, :firefox_ipad, :firefox_android, :safari, :safari_macos, :safari_iphone, :safari_ipad, :edge, :linux, :macos, :windows, :iphone, :ipad, :android, nil) (defaults to: Support::Network::HTTP.user_agent)

Yields:

  • (agent)

    If a block is given, it will be passed the newly created Mechanize agent.

Yield Parameters:

  • agent (Mechanize)

    The new Mechanize agent.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ronin/web/mechanize.rb', line 58

def initialize(proxy:      Support::Network::HTTP.proxy,
               user_agent: Support::Network::HTTP.user_agent)
  super()

  self.verify_mode = OpenSSL::SSL::VERIFY_NONE

  if proxy
    proxy = URI(proxy)

    set_proxy(proxy.host,proxy.port,proxy.user,proxy.password)
  end

  if user_agent
    self.user_agent = case user_agent
                      when Symbol
                        Support::Network::HTTP::UserAgents[user_agent]
                      else
                        user_agent
                      end
  end

  yield self if block_given?
end