2017-04-10 1 views

Répondre

1

Ajouter method="HEAD" à votre appel AsyncHTTPClient.fetch().

response = await http_client.fetch("http://example.com", method="HEAD") 
1

En Python 3.5+:

from tornado.httpclient import AsyncHTTPClient 
from tornado.ioloop import IOLoop 

async def fetch_head(): 
    response = await http_client.fetch("http://www.google.com/") 
    print(response.headers) 
    IOLoop.current().stop() 

http_client = AsyncHTTPClient() 
IOLoop.current().add_callback(fetch_head) 
IOLoop.current().start() 

Dans le code réel, ne pas appeler "stop" jusqu'à ce que tout traitement est terminé et votre programme est prêt pour quitter.

En plus Python remplacer async/avec gen.coroutine et attendent le rendement:

from tornado import gen 

@gen.coroutine 
def fetch_head(): 
    response = yield http_client.fetch("http://www.google.com/") 
    print(response.headers) 
    IOLoop.current().stop() 
+0

Que faire si je veux faire cela toutes les secondes encore et encore? Chaque fois une URL différente? C'est pour une application d'exploration que la force brute vérifie si les pages existent. – etayluz

+0

Suivez l'exemple de [Exécution en arrière-plan] (http://www.tornadoweb.org/en/latest/guide/coroutines.html#running-in-the-background). Vous voulez récupérer l'URL dans un bloc try/catch, faire quelque chose s'il y a une exception, puis dormez pendant une seconde et bouclez. –