john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

download url

# 2013-05-26 johnpfeiffer
from twisted.internet import reactor
from twisted.web.client import downloadPage
import sys

def printError( failure ):
    print >>sys.stderr, failure

def stop( result ):
    reactor.stop()

if __name__ == '__main__':

    if len(sys.argv) != 3:
        print >>sys.stderr, "Usage: python download_resource.py <URL> <output file>"
        exit( 1 )

    d = downloadPage( sys.argv[1], sys.argv[2] )
    d.addErrback( printError )
    d.addBoth( stop )
    reactor.run()

    try:
        with open( sys.argv[2]) as file:
            for line in file:
                print line,
    except IOError as error:
        print >>sys.stderr, error

  • « kth smallest
  • download url agent »

Published

May 26, 2013

Category

python-twisted

~66 words

Tags

  • download 12
  • python 180
  • twisted 20
  • url 14