PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Mechanize Timeout Exception - How To?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Mechanize Timeout Exception - How To?

Réponse
 
LinkBack Outils de la discussion
Vieux 25/02/2008, 10h55   #1
Venkat Bagam
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Mechanize Timeout Exception - How To?

Hi all,

I am very new at scraping and using mechanize. Its all a smooth
run until I faced this problem of handling Timeout while fetching a web
page.

The Timeout::timeout() is unable to rescue this kind of errors. Here is
my code

require 'timeout'
require 'rubygems'
require 'mechanize'

agent = WWW::Mechanize.new
begin
Timeout::timeout(10) do
agent.get('http://www.r-knowsys.com') #this url doesn't exist
end
rescue Timeout::Error
puts "timeout the page doesnt exist"
end
and when I run it, the error stack is as followed

/usr/lib/ruby/1.8/net/http.rb:560:in `initialize': getaddrinfo: Name or
service not known (SocketError)
from /usr/lib/ruby/1.8/net/http.rb:560:in `open'
from /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
from /usr/lib/ruby/1.8/timeout.rb:48:in `timeout'
from /usr/lib/ruby/1.8/timeout.rb:76:in `timeout'
from /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
from /usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
from /usr/lib/ruby/1.8/net/http.rb:542:in `start'
from
/usr/lib/ruby/gems/1.8/gems/mechanize-0.6.4/lib/mechanize.rb:352:in
`fetch_page'
from
/usr/lib/ruby/gems/1.8/gems/mechanize-0.6.4/lib/mechanize.rb:143:in
`get'
from test.rb:8
from /usr/lib/ruby/1.8/timeout.rb:56:in `timeout'
from test.rb:7
>Exit code: 1



How do I handle such a case? Any appreciated.

regards,
venkat
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 25/02/2008, 11h01   #2
Arlen Cuss
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Mechanize Timeout Exception - How To?

[Note: parts of this message were removed to make it a legal post.]

Hi,

Indeed, the problem here isn't that the request is timing out - it's failing
within 10 seconds. You need to catch a SocketError - it can't find the site
www.r-knowsys.com, so it fails with a SocketError instead.

Cheers,
Arlen.

  Réponse avec citation
Vieux 27/02/2008, 08h22   #3
Venkat Bagam
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Mechanize Timeout Exception - How To?

Hi Arlen,

Thanks a lot..That worked. Seems that I need to go into the diffs of
socket error/ timeout error...

Cheers..
Venkat
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h50.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08708 seconds with 11 queries