I have this code
require \'mechanize\'
@agent = Mechanize.new
page = @agent.get(\'http://something.com/?page=1\')
next_page = page.link_with(:href=>/^?page=2/
next_page.uri.to_s
See http://www.rubydoc.info/gems/mechanize/Mechanize/Page/Link#uri-instance_method and http://ruby-doc.org/stdlib-2.4.1/libdoc/uri/rdoc/URI.html
For testing purposes, I did the following in irb:
require 'mechanize'
@agent = Mechanize.new
page = @agent.get('http://news.ycombinator.com/news')
=> #}
{meta_refresh}
{title "Hacker News"}
{iframes}
{frames}
{links
#
#
#
#
#
#
#
#
#
#
#
#
#
# Omitted for brevity...
next_page.uri
=> #
next_page.uri.to_s
=> "http://news.ycombinator.com/news2"