class WWW::Mechanize::Page
def bases
def bases @bases ||= WWW::Mechanize::List.new( search('base').map { |node| Base.new(node, @mech, self) } ) end
def content_type
def content_type response['content-type'] end
def forms
def forms @forms ||= WWW::Mechanize::List.new( search('form').map do |html_form| form = Form.new(html_form, @mech, self) form.action ||= @uri.to_s form end ) end
def frames
def frames @frames ||= WWW::Mechanize::List.new( search('frame').map { |node| Frame.new(node, @mech, self) } ) end
def iframes
def iframes @iframes ||= WWW::Mechanize::List.new( search('iframe').map { |node| Frame.new(node, @mech, self) } ) end
def initialize(uri=nil, response=nil, body=nil, code=nil, mech=nil)
def initialize(uri=nil, response=nil, body=nil, code=nil, mech=nil) super(uri, response, body, code) @mech ||= mech raise Mechanize::ContentTypeError.new(response['content-type']) unless response['content-type'] =~ /^(text\/html)|(application\/xhtml\+xml)/ @parser = @links = @forms = @meta = @bases = @frames = @iframes = nil end
def links
def links @links ||= WWW::Mechanize::List.new( %w{ a area }.map do |tag| search(tag).map do |node| Link.new(node, @mech, self) end end.flatten ) end
def meta
def meta @meta ||= WWW::Mechanize::List.new( search('meta').map do |node| next unless node['http-equiv'] && node['content'] (equiv, content) = node['http-equiv'], node['content'] if equiv && equiv.downcase == 'refresh' if content && content =~ /^\d+\s*;\s*url\s*=\s*'?([^\s']+)/i node['href'] = $1 Meta.new(node, @mech, self) end end end.compact ) end
def parser
def parser return @parser if @parser if body && response html_body = body.length > 0 ? body : '<html></html>' @parser = Mechanize.html_parser.parse(html_body) end @parser end
def pretty_print(q)
def pretty_print(q) q.object_group(self) { q.breakable q.group(1, '{url', '}') {q.breakable; q.pp uri } q.breakable q.group(1, '{meta', '}') { meta.each { |link| q.breakable; q.pp link } } q.breakable q.group(1, '{title', '}') { q.breakable; q.pp title } q.breakable q.group(1, '{iframes', '}') { iframes.each { |link| q.breakable; q.pp link } } q.breakable q.group(1, '{frames', '}') { frames.each { |link| q.breakable; q.pp link } } q.breakable q.group(1, '{links', '}') { links.each { |link| q.breakable; q.pp link } } q.breakable q.group(1, '{forms', '}') { forms.each { |form| q.breakable; q.pp form } } } end
def title
def title @title ||= if parser && search('title').inner_text.length > 0 search('title').inner_text end end