Address of Mechanize::Page?

E

endy_tj

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.
 
A

Aaron Patterson

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.
 
E

endy_tj

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,232
Messages
2,571,168
Members
47,803
Latest member
ShaunaSode

Latest Threads

Top