BirdyNet/addons/0.pageDownloader.py

27 lines
514 B
Python
Raw Normal View History

2021-03-18 15:22:56 +00:00
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