Hi,
I'm trying to parse web pages but I sometimes get 404 errors. Here's the code I use to get the web page:
result = Net::HTTP::get URI.parse(URI.escape(url))
How do I test if result
is a 404 error code?
Thank you,
Kevin
Hi,
I'm trying to parse web pages but I sometimes get 404 errors. Here's the code I use to get the web page:
result = Net::HTTP::get URI.parse(URI.escape(url))
How do I test if result
is a 404 error code?
Thank you,
Kevin
Rewrite your code like this:
uri = URI.parse(url)
result = Net::HTTP.start(uri.host, uri.port) { |http| http.get(uri.path) }
puts result.code
puts result.body
That will print the status code followed by the body.