de análisis HTTPResponse con NokogiriRubí análisis HTTPResponse con Nokogiri
Hola, Tengo problemas para analizar objetos HttpResponse con Nokogiri.
puedo utilizar esta función para buscar un sitio web en:
buscar un enlace
def fetch(uri_str, limit = 10)
# You should choose better exception.
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
url = URI.parse(URI.encode(uri_str.strip))
puts url
#get path
req = Net::HTTP::Get.new(url.path,headers)
#start TCP/IP
response = Net::HTTP.start(url.host,url.port) { |http|
http.request(req)
}
case response
when Net::HTTPSuccess
then #print final redirect to a file
puts "this is location" + uri_str
puts "this is the host #{url.host}"
puts "this is the path #{url.path}"
return response
# if you get a 302 response
when Net::HTTPRedirection
then
puts "this is redirect" + response['location']
return fetch(response['location'],aFile, limit - 1)
else
response.error!
end
end
html = fetch("http://www.somewebsite.com/hahaha/")
puts html
noko = Nokogiri::HTML(html)
cuando hago esto impresiones html un montón de galimatías y Nokogiri se queja de que "node_set debe ser un Nokogiri :: XML :: nodeset
Si alguien puede ofrecer ayuda sería muy apreciada
usted debe utilizar en lugar de mecanizar este lío caliente. Se ocupa de los redireccionamientos y trata con las codificaciones para usted. – pguardiario