[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Address of Mechanize::Page?

endy_tj

2/4/2007 10:39:00 AM

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.

--
Endy

2 Answers

Aaron Patterson

2/4/2007 10:57:00 PM

0

On Sun, Feb 04, 2007 at 07:40:09PM +0900, endy_tj wrote:
> 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.

Try this:

puts page.uri

I think that should work for you.

--
Aaron Patterson
http://tenderlovem...

endy_tj

2/6/2007 5:04:00 AM

0

On Feb 5, 5:57 am, Aaron Patterson <aaron_patter...@speakeasy.net>
wrote:
> On Sun, Feb 04, 2007 at 07:40:09PM +0900, endy_tj wrote:
> > 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.
>
> Try this:
>
> puts page.uri
>
> 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.