Bonjour,
A titre d'indication j'ai commencé le Python hier soir
Vraiment très très sympa ce langage, le seul problème c'est les expressions régulières, c'est un peu cauchemardesque
J'en arrive à mon problème. Je suis en train de faire un jeu de programmation python sur internet :
http://www.pythonchallenge.com/
J'en suis à l'épreuve 4. On dispose d'un lien de ce type (url légèrement changé) :
quand on arrive sur cette page, on obtient ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 http://www.pythonchallenge.com/pc/def/xxx.php?nothing=12345
il faut ensuite concaténer le chiffre et l'url :and the next nothing is 92512
pour l'instant je ne sais pas où cela s'arrête...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 http://www.pythonchallenge.com/pc/def/xxx.php?nothing=92512
voilà mon code actuel :
voilà le retour après la première itération :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 import urllib2 import re urlist = ['http://www.pythonchallenge.com/pc/def/xxx.php?nothing=', '12345'] while urlist[1] != 0: #je ne connais pas la condition d'arrêt... for ligne in urllib2.urlopen(urlist[0] + urlist[1]): if "nothing" in ligne: print ligne urlist[1] = "".join(re.findall('[\d]', ligne)) # [\d] = [0-9] print urlist[1]
ca fonctionne pendant un certains temps mais arrive un moment ou j'ai ceci :and the next nothing is 92512
92512
et print urlist[1] me retourne : 6106753522text. One example is 61067. Look only for the next nothing and the next nothing is 53522(normal me direz vous
)
Quelle expression puis-je écrire pour que urlist[1] vale uniquement le chiffre qui se trouve après "and the next nothing is " ?
j'ai vu un "opérateur" \Z qui fonctionne pour la fin d'une chaine mais impossible de m'en servir correctement...
Merci à vous![]()
Partager