Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
431 B

  1. from urllib.request import urlopen
  2. import time
  3. class WebPage:
  4. def __init__(self, url):
  5. self.url = url
  6. self._content = None
  7. @property
  8. def content(self):
  9. now = time.time()
  10. if not self._content:
  11. print("Retrieving new page...")
  12. self._content = urlopen(self.url).read()
  13. print("Got page in {} seconds".format(time.time() - now))
  14. return self._content