The following is the code for extracting the html contents of a
website. I have included the code in case url redirect and BadRequest
#getting the HTTP response from ‘uri’
response = Net::HTTP.get_response(uri)
# if the url is redirecting then fetch the contents of the
when Net::HTTPRedirection then uri = URI.parse(response[‘Location’])
in case of a bad request error
when Net::HTTPBadRequest then http = Net::HTTP.start(uri.host,
#getting the html data by setting the path as ‘/’ and using a user
response = http.get("/", “User-Agent”=>“Mozilla/4.0 (compatible; MSIE
5.5; Windows NT 5.0)”)
data = response.body
My tutor is saying that there is a duplication in the above code. ie.
code for html reading is specified twice without any purpose and it
should be removed. I’ve no idea where there is a mistake. I’m a newbee
to ruby and i don’t understand the problem correctly or where things
went wrong. Can anyone please help me to find the mistake.
Thanks in advance.