N
nicholas4
I am new to ruby and am trying to write a simple script that takes a
url and prints the suorce code for the url.
Here's my code:
require 'net/https'
require 'uri'
def get_html(url)
page = Net::HTTP.get_response(URI.parse(url).host,
URI.parse(url).path).body
return page
end
url = "http://www.cnn.com/2006/POLITICS/06/07/nsa/index.html"
html_source = get_html(url)
print html_source
When I send the request for the page, how do I specify the user agent?
Thanks!
url and prints the suorce code for the url.
Here's my code:
require 'net/https'
require 'uri'
def get_html(url)
page = Net::HTTP.get_response(URI.parse(url).host,
URI.parse(url).path).body
return page
end
url = "http://www.cnn.com/2006/POLITICS/06/07/nsa/index.html"
html_source = get_html(url)
print html_source
When I send the request for the page, how do I specify the user agent?
Thanks!