diff --git a/BirdyNet.py b/BirdyNet.py index 0efe3a6..d21ecf1 100644 --- a/BirdyNet.py +++ b/BirdyNet.py @@ -140,6 +140,7 @@ class browserWindow(QMainWindow): self.update() start = time.time() response = downloadPage(self.cUrlBar.text(),{"User-Agent": self.cUserAgent}) + self.cUrlBar.setText(response["url"]) end = time.time() print("Downloading page: " +str(end - start)) diff --git a/addons/0.pageDownloader.py b/addons/0.pageDownloader.py index 110061a..3a097cf 100644 --- a/addons/0.pageDownloader.py +++ b/addons/0.pageDownloader.py @@ -12,10 +12,20 @@ def downloadPage(url,headers = False): "body": None, "headers": [] } - request = urllib.request.Request(url,headers=headers) - requestHandler = None + + class rdrh(urllib.request.HTTPRedirectHandler): + def redirect_request(self,req,fp,code,msg,hdrs,newurl): + response["url"] = newurl + return urllib.request.HTTPRedirectHandler.redirect_request(self, req, fp, code, msg, hdrs, newurl) + + opener = urllib.request.build_opener(rdrh) + outHeaders = [] + for header in headers: + outHeaders.append((header,headers[header])) + opener.addheaders = outHeaders + requestHandler = opener.open(url) + try: - requestHandler = urllib.request.urlopen(request) response["headers"] = requestHandler.getheaders() response["body"] = requestHandler.read() except urllib.error.HTTPError as e: