Fetch and save a remote file in python
It's that simple :)
bash-3.00$ python
Python 2.4.1 (#2, Aug 25 2005, 18:20:57)
[GCC 4.0.1 (4.0.1-2mdk for Mandriva Linux release 2006.0)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> import urllib.ur
urllib.url2pathname urllib.urlencode urllib.urlretrieve
urllib.urlcleanup urllib.urlopen
>>> urllib.urlopen('http://hpux.connect.org.uk/hppd/auto/')
>>> fileobject = urllib.urlopen('http://hpux.connect.org.uk/hppd/auto/')
>>> file
file fileobject
>>> fileobject.
fileobject.__class__ fileobject.__repr__ fileobject.headers fileobject.readlines
fileobject.__doc__ fileobject.close fileobject.info fileobject.url
fileobject.__init__ fileobject.fileno fileobject.next
fileobject.__iter__ fileobject.fp fileobject.read
fileobject.__module__ fileobject.geturl fileobject.readline
>>> fileobject.rea
fileobject.read fileobject.readline fileobject.readlines
>>> str = fileobject.read()
>>> output = open('/tmp/toto32', 'w')
>>> output.write(str)
>>>
1 Comments:
Operation time out ca veut dire que le serveur hebergeant le site est down je pense.
Reessaye avec 'http://www.google.com'
Sinon c'est que ta version de python n'est pas compatible (2.2), maic ca semble hyper bizare car urllib c'est vieux comme le monde.
Post a Comment
<< Home