Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

une lib HTTP permettant d'obtenir le code HTTP?

4 réponses
Avatar
Kevin Denis
Bonjour,

sous python 2.4.2 je dois écrire un script qui doit
récupérer le code retour HTTP de différentes pages web.

Je dois tester aussi bien:
http://www.domaine.com/
que
http://www.domaine.com/dir/subdir/page.html

et je dois trouver pour chacune des ces URLs le code retour HTTP
pour celles-ci. Par exemple,
http://www.domaine.com Code 200 OK
http://www.domaine.com/dir/subdir/page.html Code 404 Not Found
ou les codes 302, etc...

Savez vous s'il existe une lib toute prête qui fait déjà ça ou
approchant?

Merci
--
Kevin

4 réponses

Avatar
Alain Ketterlin
Kevin Denis writes:

sous python 2.4.2 je dois écrire un script qui doit
récupérer le code retour HTTP de différentes pages web.

Je dois tester aussi bien:
http://www.domaine.com/" target="_blank" class="text-blue hover:opacity-90 " style="word-break: break-all;" rel="noopener nofollow">http://www.domaine.com/
que
http://www.domaine.com/" target="_blank" class="text-blue hover:opacity-90 " style="word-break: break-all;" rel="noopener nofollow">http://www.domaine.com/dir/subdir/page.html

et je dois trouver pour chacune des ces URLs le code retour HTTP
pour celles-ci. Par exemple,
http://www.domaine.com Code 200 OK
http://www.domaine.com/" target="_blank" class="text-blue hover:opacity-90 " style="word-break: break-all;" rel="noopener nofollow">http://www.domaine.com/dir/subdir/page.html Code 404 Not Found
ou les codes 302, etc...

Savez vous s'il existe une lib toute prête qui fait déjà ça ou
approchant?



http://lmgtfy.com/?q=python+lib+http&l=1

-- Alain.
Avatar
Kevin Denis
Le 24-02-2012, Alain Ketterlin a écrit :

sous python 2.4.2



http://lmgtfy.com/?q=python+lib+http&l=1



ha ha.
Bon, je cherche avec urrlib, mais avec python 2.4:
obj = urllib.urlopen("http://domaine.tld")
obj.getcode()






Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: addinfourl instance has no attribute 'getcode'







--
Kevin
Avatar
Thomas NOEL
On 24 fév, 09:52, Alain Ketterlin wrote:
Kevin Denis writes:
>http://www.domaine.com Code 200 OK
>http://www.domaine.com/dir/subdir/page.htmlCode 404 Not Found
> ou les codes 302, etc...
> Savez vous s'il existe une lib toute prête qui fait déjà ça ou
> approchant?
http://lmgtfy.com/?q=python+lib+http&l=1



oui, et aussi http://docs.python-requests.org

--
Thomas
Avatar
Kevin Denis
Le 24-02-2012, Kevin Denis a écrit :
sous python 2.4.2







Avec httplib, ça fonctionne. En 2.4.2 il n'y a pas de notion de
timeout, dommage:
c = httplib.HTTPConnection("10.0.0.47")
c.request("HEAD", "/")
r = c.getresponse()
print r.status






200
--
Kevin