[Tutor] Urllib Problem

Steven D'Aprano steve at pearwood.info
Fri Jul 29 15:16:59 CEST 2011


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



More information about the Tutor mailing list