26 lines
589 B
Python
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 |