Class | WWW::Mechanize::Page |
In: |
lib/www/mechanize/monkey_patch.rb
lib/www/mechanize/page/base.rb lib/www/mechanize/page/frame.rb lib/www/mechanize/page/link.rb lib/www/mechanize/page/meta.rb lib/www/mechanize/page.rb |
Parent: | Object |
This class encapsulates an HTML page. If Mechanize finds a content type of ‘text/html’, this class will be instantiated and returned.
require 'rubygems' require 'mechanize' agent = WWW::Mechanize.new agent.get('http://google.com/').class #=> WWW::Mechanize::Page
pretty_inspect | -> | inspect |
mech | [RW] |
# File lib/www/mechanize/page.rb, line 25 25: def initialize(uri=nil, response=nil, body=nil, code=nil, mech=nil) 26: super(uri, response, body, code) 27: @mech ||= mech 28: 29: raise Mechanize::ContentTypeError.new(response['content-type']) unless 30: response['content-type'] =~ /^(text\/html)|(application\/xhtml\+xml)/ 31: 32: @parser = @links = @forms = @meta = @bases = @frames = @iframes = nil 33: end
# File lib/www/mechanize/page.rb, line 124 124: def bases 125: @bases ||= WWW::Mechanize::List.new( 126: search('base').map { |node| Base.new(node, @mech, self) } 127: ) 128: end
Get the content type
# File lib/www/mechanize/page.rb, line 54 54: def content_type 55: response['content-type'] 56: end
# File lib/www/mechanize/page.rb, line 99 99: def forms 100: @forms ||= WWW::Mechanize::List.new( 101: search('form').map do |html_form| 102: form = Form.new(html_form, @mech, self) 103: form.action ||= @uri.to_s 104: form 105: end 106: ) 107: end
# File lib/www/mechanize/page.rb, line 130 130: def frames 131: @frames ||= WWW::Mechanize::List.new( 132: search('frame').map { |node| Frame.new(node, @mech, self) } 133: ) 134: end
# File lib/www/mechanize/page.rb, line 136 136: def iframes 137: @iframes ||= WWW::Mechanize::List.new( 138: search('iframe').map { |node| Frame.new(node, @mech, self) } 139: ) 140: end
# File lib/www/mechanize/page.rb, line 89 89: def links 90: @links ||= WWW::Mechanize::List.new( 91: %w{ a area }.map do |tag| 92: search(tag).map do |node| 93: Link.new(node, @mech, self) 94: end 95: end.flatten 96: ) 97: end
# File lib/www/mechanize/page.rb, line 109 109: def meta 110: @meta ||= WWW::Mechanize::List.new( 111: search('meta').map do |node| 112: next unless node['http-equiv'] && node['content'] 113: (equiv, content) = node['http-equiv'], node['content'] 114: if equiv && equiv.downcase == 'refresh' 115: if content && content =~ /^\d+\s*;\s*url\s*=\s*'?([^\s']+)/i 116: node['href'] = $1 117: Meta.new(node, @mech, self) 118: end 119: end 120: end.compact 121: ) 122: end