[Tutor] Urllib Problem

2011-07-29 Thread George Anonymous
I am trying to make a simple programm with Python 3,that tries to open
differnet pages from a wordlist and prints which are alive.Here is the code:
from urllib import request
fob=open('c:/passwords/pass.txt','r')
x = fob.readlines()
for i in x:
urllib.request.openurl('www.google.gr/' + i)

But it doesent work.Whats the problem?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Urllib Problem

2011-07-29 Thread Karim

On 07/29/2011 11:52 AM, George Anonymous wrote:
I am trying to make a simple programm with Python 3,that tries to open 
differnet pages from a wordlist and prints which are alive.Here is the 
code:

from urllib import request
fob=open('c:/passwords/pass.txt','r')
x = fob.readlines()
for i in x:
urllib.request.openurl('www.google.gr/ http://www.google.gr/' + i)

But it doesent work.Whats the problem?



Please give the exception error you get?!
And you should have in the html header
the html code error number which gives
you the fail answer from the server.

Cheers
Karim



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Urllib Problem

2011-07-29 Thread Alexander
On Fri, Jul 29, 2011 at 5:58 AM, Karim karim.liat...@free.fr wrote:

 **
 On 07/29/2011 11:52 AM, George Anonymous wrote:

 I am trying to make a simple programm with Python 3,that tries to open
 differnet pages from a wordlist and prints which are alive.Here is the code:
 from urllib import request
 fob=open('c:/passwords/pass.txt','r')
 x = fob.readlines()
 for i in x:
 urllib.request.openurl('www.google.gr/' + i)

 But it doesent work.Whats the problem?


 Please give the exception error you get?!
 And you should have in the html header
 the html code error number which gives
 you the fail answer from the server.

 Cheers
 Karim

 As Karim noted you'll want to mention any exceptions you are getting. I'm
not sure what it is you are trying to do with your code. If you'd like to
try to open each line and try something if it works else an exception the
code may read something similar to:

fob = open('C:/passwords/pass.txt','r')
fob_rlines = fob.readlines()
for line in fob_rlines:
try:
#whatever it is you would like to do with each line
except Exception: #where code didn't work and an exception occured
#whatever you would like to do when a particular *Exception* occurs
Hope that helps,
Alexander


 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription 
 options:http://mail.python.org/mailman/listinfo/tutor



 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Urllib Problem

2011-07-29 Thread Steven D'Aprano

George Anonymous wrote:

I am trying to make a simple programm with Python 3,that tries to open
differnet pages from a wordlist and prints which are alive.Here is the code:
from urllib import request
fob=open('c:/passwords/pass.txt','r')
x = fob.readlines()
for i in x:
urllib.request.openurl('www.google.gr/' + i)

But it doesent work.Whats the problem?



A guessing game! I LOVE guessing games!!! :)

Let's seen let me guess what you mean by doesn't work:

- the computer locks up and sits there until you hit the restart switch
- the computer gives a Blue Screen Of Death
- Python raises an exception
- Python downloads the Yahoo website instead of Google
- something else


My guess is... you're getting a NameError exception, like this one:


 from urllib import request
 x = urllib.request.openurl('www.google.com')
Traceback (most recent call last):
  File stdin, line 1, in module
NameError: name 'urllib' is not defined


Am I close?


You need to use request.urlopen, not urllib.request.openurl.

That's your *first* problem. There are more. Come back if you need help 
with the others, and next time, don't make us play guessing games. Show 
us the code you use -- copy and paste it, don't retype it from memory -- 
what you expect should happen, and what actually happens instead.





--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] urllib problem

2010-10-12 Thread Roelof Wobben


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 ?
 
Roelof 
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib problem

2010-10-12 Thread Evert Rol
 I have this program :
 
 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.

I think number will change; *unless* you happen to retrieve the same number 
every time, even when you access a different url.
What is the result when you run this program, ie, the output of your print 
statements (then, also, print url)?
And, how can url change, but volgende not? Since url depends on volgende.

Btw, it may be better to use parentheses in your regular expression to 
explicitly group whatever you want to match, though the above will work (since 
it groups the whole match). But Python has this Explicit is better than 
implicit thing.

Cheers,

  Evert

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib problem

2010-10-12 Thread Steven D'Aprano
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@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib problem

2010-10-12 Thread Steven D'Aprano
On Tue, 12 Oct 2010 11:58:03 pm Steven D'Aprano wrote:
 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.ph
 p? 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.

Wait, sorry, inhoud should change... I missed the line inhoud = f.read()

My mistake, sorry about that. However, I can now see what is going 
wrong. Your regular expression only looks for a single digit:

re.search('[0-9]', inhoud)

If you want any number of digits, you need '[0-9]+' instead.


Starting from the first URL:

 f = urllib.urlopen(
... http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=6;)
 inhoud = f.read()
 f.close()
 print inhoud
and the next nothing is 87599


but:

 nummer = re.search('[0-9]', inhoud)
 nummer.group()
'8'

See, you only get the first digit. Then looking up the page with 
nothing=8 gives a first digit starting with 5, and then you get stuck 
on 5 forever:

 urllib.urlopen(
... http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=8;).read() 
'and the next nothing is 59212'
 urllib.urlopen(
... http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=5;).read() 
'and the next nothing is 51716'


You need to add a + to the regular expression, which means one or more 
digits instead of a single digit.



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib problem

2010-10-12 Thread Roelof Wobben




 From: st...@pearwood.info
 To: tutor@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@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

  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib problem

2010-10-12 Thread Roelof Wobben




 From: st...@pearwood.info
 To: tutor@python.org
 Date: Wed, 13 Oct 2010 01:51:16 +1100
 Subject: Re: [Tutor] urllib problem

 On Tue, 12 Oct 2010 11:58:03 pm Steven D'Aprano wrote:
  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.ph
  p? 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.

 Wait, sorry, inhoud should change... I missed the line inhoud = f.read()

 My mistake, sorry about that. However, I can now see what is going
 wrong. Your regular expression only looks for a single digit:

 re.search('[0-9]', inhoud)

 If you want any number of digits, you need '[0-9]+' instead.


 Starting from the first URL:

  f = urllib.urlopen(
 ... http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=6;)
  inhoud = f.read()
  f.close()
  print inhoud
 and the next nothing is 87599


 but:

  nummer = re.search('[0-9]', inhoud)
  nummer.group()
 '8'

 See, you only get the first digit. Then looking up the page with
 nothing=8 gives a first digit starting with 5, and then you get stuck
 on 5 forever:

  urllib.urlopen(
 ... http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=8;).read()
 'and the next nothing is 59212'
  urllib.urlopen(
 ... http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=5;).read()
 'and the next nothing is 51716'


 You need to add a + to the regular expression, which means one or more
 digits instead of a single digit.



 --
 Steven D'Aprano
 ___
 Tutor maillist - Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

 
Hoi Steven, 
 
Finally solved this puzzle.
Now the next one of the 33 puzzles.
 
Roelof
  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] urllib problem

2010-10-12 Thread Alan Gauld


Roelof Wobben rwob...@hotmail.com wrote


Finally solved this puzzle.
Now the next one of the 33 puzzles.


Don;t be surprised if you get stuck. Python Challenge is quite tricky
and is deliberately designed to make you explore parts of the
standard library you might not otherwise find. Expect to do a lot
of reading in the documebntation.

Its really targeted at intermediate rather than novice
programmers IMHO.

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor