27 lines
514 B
Python
27 lines
514 B
Python
|
global urllib
|
||
|
import urllib.request
|
||
|
|
||
|
global downloadPage
|
||
|
def downloadPage(url,headers = False):
|
||
|
if not headers: headers = {}
|
||
|
request = urllib.request.Request(url,headers=headers)
|
||
|
response = None
|
||
|
|
||
|
try:
|
||
|
response = urllib.request.urlopen(request)
|
||
|
except urllib.error.HTTPError as e:
|
||
|
response = e
|
||
|
|
||
|
# process headers
|
||
|
headers = response.getheaders()
|
||
|
headersOut = {}
|
||
|
for hl in headers:
|
||
|
headersOut[hl[0]] = hl[1]
|
||
|
|
||
|
out = {
|
||
|
"url": url,
|
||
|
"headers": headersOut,
|
||
|
"body": response.read()
|
||
|
}
|
||
|
|
||
|
return out
|