Problème d'expression régulière
Bonjour,
A titre d'indication j'ai commencé le Python hier soir :D
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é ;)) :
Code:
1 2
|
http://www.pythonchallenge.com/pc/def/xxx.php?nothing=12345 |
quand on arrive sur cette page, on obtient ceci :
Citation:
and the next nothing is 92512
il faut ensuite concaténer le chiffre et l'url :
Code:
1 2
|
http://www.pythonchallenge.com/pc/def/xxx.php?nothing=92512 |
pour l'instant je ne sais pas où cela s'arrête...
voilà mon code actuel :
Code:
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] |
voilà le retour après la première itération :
Citation:
and the next nothing is 92512
92512
ca fonctionne pendant un certains temps mais arrive un moment ou j'ai ceci :
Citation:
text. One example is 61067. Look only for the next nothing and the next nothing is 53522
et print urlist[1] me retourne : 6106753522 :!: (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 :D