title: Nokogiri in Rails - Scrape results of multiple pages
body: <p>I'm using Nokogiri in Rails while attempting to get the results from multiple pages of a Subreddit but I can only get the first page. Any ideas on how to acheive this. I can't seem to figure this out. Here's my current RedditScraper class: </p>
  
  <pre><code>require 'nokogiri'
  require 'open-uri'
  
  class RedditScraper
  
  def initialize
   @headline = []
  end
  
  def fetch_reddit_headlines
   page = Nokogiri::HTML(open("http://www.reddit.com/r/ruby"))
   page.css('a.title').each do |link|
     if link['href'].include?('http')
      @headline &lt;&lt; { content: link.content, href: link['href'] }
     else
      @headline &lt;&lt; { content: link.content, href: "http://reddit.com" + link['href'] }
     end
    end
    @headline
   end
  end
  </code></pre>
  
  <p><strong>JUST ADDED</strong></p>
  
  <p>Controller method: </p>
  
  <pre><code>def index
   @fetch_reddit = RedditScraper.new.fetch_reddit_headlines    
  end
  </code></pre>
  
  <p>View code: </p>
  
  <pre><code>&lt;ol&gt;
   &lt;% @fetch_reddit.each do |url| %&gt;
    &lt;li&gt;&lt;%= link_to url[:content], url[:href], target: '_' %&gt;&lt;/li&gt;
   &lt;% end %&gt;
  &lt;/ol&gt;
  </code></pre>
  
  <p><strong>Screenshot</strong></p>
  
  <p><img src="https://i.stack.imgur.com/mYjhv.png" alt="enter image description here"></p>