Debian Codegraph @

docs/web/examples/dlpage.py

raw
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 This example demonstrates how to use downloadPage.
6
7 Usage:
8 $ python dlpage.py <url>
9
10 Don't forget the http:// when you type a URL!
11 """
12
13 import sys
14
15 from twisted.internet import reactor
16 from twisted.python.util import println
17 from twisted.web.client import downloadPage
18
19 # The function downloads a page and saves it to a file, in this case, it saves
20 # the page to "foo".
21 url = sys.argv[1].encode("ascii")
22 downloadPage(url, "foo").addCallbacks(
23 lambda value: reactor.stop(),
24 lambda error: (println("an error occurred", error), reactor.stop()),
25 )
26 reactor.run()