Reputation: 3105
The ruby code that should get the source code of a given website doesn't work. It says that the site does not exist.
require 'uri'
require 'net/http'
uri = URI.parse("http://nice.com/careers?category=170")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response=http.request(request)
@data = response.body
It does work with other sites.
Upvotes: 1
Views: 52
Reputation: 32758
I always like to check stuff using curl
on the command line.
In this case it turns out a request to http://nice.com/careers?category=170
gives you a HTTP 301
redirect to the same domain but with www.
:
curl -I "http://nice.com/careers?category=170"
HTTP/1.1 301 Moved Permanently
Date: Sun, 30 Mar 2014 20:50:00 GMT
Server: Apache
Location: http://www.nice.com/careers?category=170
So update your code to to use the www.nice.com
domain.
Also, you can implement logic to follow redirects, like in this answer:
https://stackoverflow.com/a/6934503/25398
Upvotes: 2