Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Attempt to modernize examples, but I'm not sure if they all still wor…

…k with my changes. Issue #108
  • Loading branch information...
commit 442ceaefa344f454ab1bcbbd76018b8a435f5de2 1 parent 5e03824
@drbrain drbrain authored
View
13 examples/flickr_upload.rb
@@ -1,23 +1,22 @@
-$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
-
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
# Get the flickr sign in page
-page = agent.get('http://flickr.com/signin/flickr/')
+page = agent.get 'http://flickr.com/signin/flickr/'
# Fill out the login form
-form = page.form_with(:name => 'flickrloginform')
+form = page.form_with :name => 'flickrloginform'
form.email = ARGV[0]
form.password = ARGV[1]
-page = agent.submit(form)
+form.submit
# Go to the upload page
-page = agent.click page.link_with(:text => 'Upload')
+page = page.link_with(:text => 'Upload').click
# Fill out the form
form = page.forms.action('/photos_upload_process.gne').first
form.file_uploads.name('file1').first.file_name = ARGV[2]
-agent.submit(form)
+form.submit
+
View
2  examples/mech-dump.rb
@@ -1,5 +1,3 @@
-$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
-
require 'rubygems'
require 'mechanize'
View
2  examples/proxy_req.rb
@@ -1,5 +1,3 @@
-$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
-
require 'rubygems'
require 'mechanize'
View
4 examples/rubyforge.rb
@@ -1,5 +1,3 @@
-$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
-
# This example logs a user in to rubyforge and prints out the body of the
# page after logging the user in.
require 'rubygems'
@@ -17,6 +15,6 @@
form.form_pw = ARGV[1]
# Submit the form
-page = agent.submit(form, form.buttons.first)
+page = form.submit form.buttons.first
puts page.body # Print out the body
View
5 examples/spider.rb
@@ -1,5 +1,3 @@
-$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
-
require 'rubygems'
require 'mechanize'
@@ -7,13 +5,14 @@
stack = agent.get(ARGV[0]).links
while l = stack.pop
+ next unless l.uri
host = l.uri.host
next unless host.nil? or host == agent.history.first.uri.host
next if agent.visited? l.href
puts "crawling #{l.uri}"
begin
- page = agent.click(l)
+ page = l.click
next unless Mechanize::Page === page
stack.push(*page.links)
rescue Mechanize::ResponseCodeError
View
2  lib/mechanize/form/field.rb
@@ -29,7 +29,7 @@ def <=> other
return -1 if Hash === other.node
node <=> other.node
end
-
+
# This method is a shortcut to get field's DOM id.
# Common usage: form.field_with(:dom_id => "foo")
def dom_id
Please sign in to comment.
Something went wrong with that request. Please try again.