From b4e8d8d023fac8f4141e5ea76658c91b84f3ffa9 Mon Sep 17 00:00:00 2001 From: Akash <64683866+akamhy@users.noreply.github.com> Date: Sun, 19 Jul 2020 19:53:03 +0530 Subject: [PATCH] Update wrapper.py --- waybackpy/wrapper.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/waybackpy/wrapper.py b/waybackpy/wrapper.py index 04fd2dc..204d6b9 100644 --- a/waybackpy/wrapper.py +++ b/waybackpy/wrapper.py @@ -93,24 +93,29 @@ class Url(): def get(self, url=None, user_agent=None, encoding=None): """Returns the source code of the supplied URL. Auto detects the encoding if not supplied.""" + if not url: url = self.clean_url() if not user_agent: user_agent = self.user_agent + hdr = { 'User-Agent' : '%s' % user_agent } req = Request(url, headers=hdr) #nosec + try: resp=urlopen(req) #nosec - except URLError: + except Exception: try: resp=urlopen(req) #nosec - except URLError as e: - raise HTTPError(e) + except Exception as e: + raise WaybackError(e) + if not encoding: try: encoding= resp.headers['content-type'].split('charset=')[-1] except AttributeError: encoding = "UTF-8" + return resp.read().decode(encoding.replace("text/html", "UTF-8", 1)) def near(self, **kwargs):