Sto provando a usare Python per scaricare il codice sorgente HTML di un sito Web ma sto ricevendo questo errore.AttributeError: l'oggetto 'module' non ha attributo 'urlopen'
Traceback (most recent call last):
File "C:\Users\Sergio.Tapia\Documents\NetBeansProjects\DICParser\src\WebDownload.py", line 3, in file = urllib.urlopen(" http://www.python.org ") AttributeError: 'module' object has no attribute 'urlopen'
Sto seguendo la guida qui: http://www.boddie.org.uk/python/HTML.html
import urllib
file = urllib.urlopen("http://www.python.org")
s = file.read()
f.close()
#I'm guessing this would output the html source code?
print(s)
sto usando Python 3, grazie per l'aiuto!
Ciao Eumiro, usando l'istruzione 'with' in Python, suppongo che chiuda automaticamente la connessione una volta terminato l'utilizzo? Simile a una dichiarazione di utilizzo in C#? –
@Sergio: esattamente! E attraverso il rientro vedi dove il tuo file è ancora aperto. – eumiro
Grazie per l'aiuto –