Skip to content

Commit

Permalink
typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Erkan-Yilmaz committed Mar 9, 2012
1 parent 2b728f3 commit 2c719bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions EXAMPLES.rdoc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Upload a file to flickr.


== Pluggable Parsers == Pluggable Parsers


Lets say you want HTML pages to automatically be parsed with Rubyful Soup. Let's say you want HTML pages to automatically be parsed with Rubyful Soup.
This example shows you how: This example shows you how:


require 'rubygems' require 'rubygems'
Expand Down Expand Up @@ -119,7 +119,7 @@ Beautiful Soup for that page.


Mechanize#transact runs the given block and then resets the page history. I.e. Mechanize#transact runs the given block and then resets the page history. I.e.
after the block has been executed, you're back at the original page; no need after the block has been executed, you're back at the original page; no need
count how many times to call the back method at the end of a loop (while to count how many times to call the back method at the end of a loop (while
accounting for possible exceptions). accounting for possible exceptions).


This example also demonstrates subclassing Mechanize. This example also demonstrates subclassing Mechanize.
Expand Down
26 changes: 13 additions & 13 deletions GUIDE.rdoc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ Mechanize stored any cookies that were set, and followed any redirects that
google may have sent. The agent gave us back a page that we can use to google may have sent. The agent gave us back a page that we can use to
scrape data, find links to click, or find forms to fill out. scrape data, find links to click, or find forms to fill out.


Next, lets try finding some links to click. Next, let's try finding some links to click.


== Finding Links == Finding Links


Mechanize returns a page object whenever you get a page, post, or submit a Mechanize returns a page object whenever you get a page, post, or submit a
form. When a page is fetched, the agent will parse the page and put a list form. When a page is fetched, the agent will parse the page and put a list
of links on the page object. of links on the page object.


Now that we've fetched google's homepage, lets try listing all of the links: Now that we've fetched google's homepage, let's try listing all of the links:


page.links.each do |link| page.links.each do |link|
puts link.text puts link.text
end end


We can list the links, but Mechanize gives a few shortcuts to help us find a We can list the links, but Mechanize gives a few shortcuts to help us find a
link to click on. Lets say we wanted to click the link whose text is 'News'. link to click on. Let's say we wanted to click the link whose text is 'News'.
Normally, we would have to do this: Normally, we would have to do this:


page = agent.page.links.find { |l| l.text == 'News' }.click page = agent.page.links.find { |l| l.text == 'News' }.click
Expand All @@ -65,13 +65,13 @@ Or chain them together to find a link with certain text and certain href:


page.link_with(:text => 'News', :href => '/something') page.link_with(:text => 'News', :href => '/something')


These shortcuts that mechanize provides are available on any list that you These shortcuts that Mechanize provides are available on any list that you
can fetch like frames, iframes, or forms. Now that we know how to find and can fetch like frames, iframes, or forms. Now that we know how to find and
click links, lets try something more complicated like filling out a form. click links, let's try something more complicated like filling out a form.


== Filling Out Forms == Filling Out Forms


Lets continue with our google example. Here's the code we have so far: Let's continue with our google example. Here's the code we have so far:
require 'rubygems' require 'rubygems'
require 'mechanize' require 'mechanize'


Expand All @@ -83,17 +83,17 @@ that has a couple buttons and a few fields:


pp page pp page


Now that we know the name of the form, lets fetch it off the page: Now that we know the name of the form, let's fetch it off the page:


google_form = page.form('f') google_form = page.form('f')


Mechanize lets you access form input fields in a few different ways, but the Mechanize lets you access form input fields in a few different ways, but the
most convenient is that you can access input fields as accessors on the most convenient is that you can access input fields as accessors on the
object. So lets set the form field named 'q' on the form to 'ruby mechanize': object. So let's set the form field named 'q' on the form to 'ruby mechanize':


google_form.q = 'ruby mechanize' google_form.q = 'ruby mechanize'


To make sure that we set the value, lets pretty print the form, and you should To make sure that we set the value, let's pretty print the form, and you should
see a line similar to this: see a line similar to this:


#<Mechanize::Field:0x1403488 @name="q", @value="ruby mechanize"> #<Mechanize::Field:0x1403488 @name="q", @value="ruby mechanize">
Expand All @@ -109,7 +109,7 @@ clicking the 'Google Search' button. If we had submitted the form without
a button, it would be like typing in the text field and hitting the return a button, it would be like typing in the text field and hitting the return
button. button.


Lets take a look at the code all together: Let's take a look at the code all together:


require 'rubygems' require 'rubygems'
require 'mechanize' require 'mechanize'
Expand All @@ -121,7 +121,7 @@ Lets take a look at the code all together:
page = agent.submit(google_form) page = agent.submit(google_form)
pp page pp page


Before we go on to screen scraping, lets take a look at forms a little more Before we go on to screen scraping, let's take a look at forms a little more
in depth. Unless you want to skip ahead! in depth. Unless you want to skip ahead!


== Advanced Form Techniques == Advanced Form Techniques
Expand All @@ -132,11 +132,11 @@ text input fields. Select fields are very similar to text fields, but they
have many options associated with them. If you select one option, mechanize have many options associated with them. If you select one option, mechanize
will de-select the other options (unless it is a multi select!). will de-select the other options (unless it is a multi select!).


For example, lets select an option on a list: For example, let's select an option on a list:


form.field_with(:name => 'list').options[0].select form.field_with(:name => 'list').options[0].select


Now lets take a look at checkboxes and radio buttons. To select a checkbox, Now let's take a look at checkboxes and radio buttons. To select a checkbox,
just check it like this: just check it like this:


form.checkbox_with(:name => 'box').check form.checkbox_with(:name => 'box').check
Expand Down

0 comments on commit 2c719bc

Please sign in to comment.