| 1 |
# Copyright (c) Twisted Matrix Laboratories |
| 2 |
# See LICENSE for details. |
| 3 |
|
| 4 |
""" |
| 5 |
This program will retrieve and print the resource at the given URL. |
| 6 |
|
| 7 |
Usage: |
| 8 |
$ python getpage.py <URL> |
| 9 |
""" |
| 10 |
|
| 11 |
import sys |
| 12 |
|
| 13 |
from twisted.internet import reactor |
| 14 |
from twisted.python.util import println |
| 15 |
from twisted.web.client import getPage |
| 16 |
|
| 17 |
url = sys.argv[1].encode("ascii") |
| 18 |
getPage(url).addCallbacks( |
| 19 |
callback=lambda value: (println(value), reactor.stop()), |
| 20 |
errback=lambda error: (println("an error occurred", error), reactor.stop()), |
| 21 |
) |
| 22 |
reactor.run() |