-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttprequests.py
51 lines (39 loc) · 953 Bytes
/
httprequests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import urllib3
import certifi
##
# GET http request on a url
# url - string
##
def https_request(url):
http = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED', ca_certs=certifi.where())
resp = http.request('GET', url)
html = html_content(resp)
resp.close()
return html
##
# retieve content of the page
# response - http request response
##
def html_content(response):
return response.data.decode('utf-8')
##
# save html content in a file
# html - HTML content
# file_name - File name
##
def save_html(html, file_name):
file = open(file_name + '.html', "w")
for line in html.splitlines():
line += u'\n'
file.write(line.encode('cp1252', errors='replace').decode('cp1252'))
file.close()
##
# read html content in a file
# file_name - File name
##
def open_html(file_name):
file = open(file_name + '.html', "r")
for line in file.readlines():
print(line)
file.close()