mechanize how to get current url

前端 未结 1 1233
醉梦人生
醉梦人生 2021-02-05 11:29

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/         


        
1条回答
  •  无人及你
    2021-02-05 12:20

    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" 
    

    0 讨论(0)
提交回复
热议问题