BirdyNet/addons/0.pageDownloader.py
2021-03-20 16:41:10 +01:00

26 lines
589 B
Python

global urllib
import urllib.request
global html
import html
global downloadPage
def downloadPage(url,headers = False):
if not headers: headers = {}
response = {
"url": url,
"body": None,
"headers": []
}
request = urllib.request.Request(url,headers=headers)
requestHandler = None
try:
requestHandler = urllib.request.urlopen(request)
response["headers"] = requestHandler.getheaders()
response["body"] = requestHandler.read()
except urllib.error.HTTPError as e:
response["body"] = e.read()
except Exception as e:
response["body"] = html.escape(e)
return response