title: How to handle 404 not found errors in Nokogiri
body: <p>I am using Nokogiri to scrape web pages. Few urls need to be guessed and returns 404 not found error when they don't exist. Is there a way to capture this exception?</p>
  
  <pre><code>http://yoursite/page/38475 #=&gt; page number 38475 doesn't exist
  </code></pre>
  
  <p>I tried the following which didn't work.</p>
  
  <pre><code>url = "http://yoursite/page/38475"
  doc = Nokogiri::HTML(open(url)) do
    begin
      rescue Exception =&gt; e
        puts "Try again later"
    end
  end
  </code></pre>