Skip to content

Instantly share code, notes, and snippets.

@alexhanh
Created December 4, 2011 15:24
Show Gist options
  • Select an option

  • Save alexhanh/1430449 to your computer and use it in GitHub Desktop.

Select an option

Save alexhanh/1430449 to your computer and use it in GitHub Desktop.
def better_fetch
data = {}
io = nil
begin
io = open(...)
rescue OpenURI::HTTPError => e
# Handle interesting http errors
rescue Timeout::Error, StandardError
# It was most likely a Net/Socket error we are not interested in, so just fail.
return nil
end
data = Nokogiri::HTML(io)
# process
return data
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment