-
Notifications
You must be signed in to change notification settings - Fork 2
/
fetch.py
33 lines (26 loc) · 970 Bytes
/
fetch.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
import requests
class Fetch:
# pass the proxies to be used
def __init__(self, proxies={}):
self.proxies = proxies
self.response = "no response"
# return json response
def json(self):
if type(self.response) != str:
return str(self.response.json())
else:
return self.response
# return text response
def text(self):
if type(self.response) != str:
return str(self.response.text)
else:
return self.response
# make a get request to the following "url" with the proxies
def get(self, url):
self.response = requests.get(url, proxies=self.proxies)
return self.text()
# make a post request to the following "url", "headers", "body" along with the proxies
def post(self, url, headers={}, body={}):
self.response = requests.post(url, proxies=self.proxies, headers=headers, data=body)
return self.text()