[Tutor] urllib problem
Roelof Wobben
rwobben at hotmail.com
Tue Oct 12 16:50:21 CEST 2010
----------------------------------------
> From: steve at pearwood.info
> To: tutor at python.org
> Date: Tue, 12 Oct 2010 23:58:03 +1100
> Subject: Re: [Tutor] urllib problem
>
> On Tue, 12 Oct 2010 11:40:17 pm Roelof Wobben wrote:
>> Hoi,
>>
>> I have this programm :
>>
>> import urllib
>> import re
>> f =
>> urllib.urlopen("http://www.pythonchallenge.com/pc/def/linkedlist.php?
>>nothing=6") inhoud = f.read()
>> f.close()
>> nummer = re.search('[0-9]', inhoud)
>> volgende = int(nummer.group())
>> teller = 1
>> while teller <= 3 :
>> url =
>> "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" +
>> str(volgende) f = urllib.urlopen(url)
>> inhoud = f.read()
>> f.close()
>> nummer = re.search('[0-9]', inhoud)
>> print "nummer is", nummer.group()
>> volgende = int(nummer.group())
>> print volgende
>> teller = teller + 1
>>
>> but now the url changes but volgende not.
>> What do I have done wrong ?
>
> Each time through the loop, you set volgende to the same result:
>
> nummer = re.search('[0-9]', inhoud)
> volgende = int(nummer.group())
>
> Since inhoud never changes, and the search never changes, the search
> result never changes, and volgende never changes.
>
>
>
> --
> Steven D'Aprano
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
Hello,
Here is the output when I print every step in the beginning :
inhoud : and the next nothing is 87599
nummer is 8
volgende is 8
and here is the output in the loop :
url is: http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=8
inhoud is and the next nothing is 59212
nummer is 5
2ste run:
url is: http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=5
inhoud is and the next nothing is 51716
nummer is 5
3ste run:
url is: http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=5
inhoud is and the next nothing is 51716
nummer is 5
4ste run:
I see the problem. It only takes the first number of the nothing.
So I have to look how to solve that.
Roelof
More information about the Tutor
mailing list