# Address of Mechanize::Page?

**URL:** <https://www.ruby-forum.com/t/address-of-mechanize-page/84425>\
**Category:** Ruby\
**Created:** [February 4, 2007, 11:41am UTC](https://www.ruby-forum.com/t/address-of-mechanize-page/84425 "2007-02-04T11:41:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![endy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f19dbf/32.png) [@endy](https://www.ruby-forum.com/u/endy)\
**Post date:** [February 4, 2007, 11:41am UTC](https://www.ruby-forum.com/t/address-of-mechanize-page/84425/1 "2007-02-04T11:41:12Z")

</div>

Hi,

I am using the Mechanize library to follow a link in a webpage.

require ‘rubygems’  
require ‘mechanize’

agent = WWW::Mechanize.new  
page = agent.get(ARGV[0])  
link1 = page.links.find{|l| l.href.match Regexp.new(ARGV[1])}  
link1.click if link1

Now I want to know the current URL of the ‘page’ variable. Is there a  
way to do that? The link’s URL cannot be used because it redirects to  
another page.

---

<div class="post-metadata">

**Author:** ![endy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f19dbf/32.png) [@endy](https://www.ruby-forum.com/u/endy)\
**Post date:** [February 4, 2007, 11:57pm UTC](https://www.ruby-forum.com/t/address-of-mechanize-page/84425/2 "2007-02-04T23:57:30Z")

</div>

On Sun, Feb 04, 2007 at 07:40:09PM +0900, endy\_tj wrote:

> link1.click if link1
> 
> Now I want to know the current URL of the ‘page’ variable. Is there a  
> way to do that? The link’s URL cannot be used because it redirects to  
> another page.

Try this:

puts page.uri

I think that should work for you.

---

<div class="post-metadata">

**Author:** ![endy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f19dbf/32.png) [@endy](https://www.ruby-forum.com/u/endy)\
**Post date:** [February 6, 2007, 6:05am UTC](https://www.ruby-forum.com/t/address-of-mechanize-page/84425/3 "2007-02-06T06:05:56Z")

</div>

On Feb 5, 5:57 am, Aaron P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > link1 = page.links.find{|l| l.href.match Regexp.new(ARGV[1])}  
> > I think that should work for you.  
> > Hey, thanks! That works.

Another question: how can I get the URI after redirection without  
loading the page? In other word, I don’t actually need the page, I  
just need the new address.
