raena-crawler-engine/tokopedia_crawler_engine/tokopedia_api.py

32 lines
678 B
Python
Raw Normal View History

2024-01-24 13:05:07 +00:00
import requests
from pathlib import Path
from tokopedia_config import Config
class api():
config = Config().get()
def post(self, url, payload):
try:
response = requests.post(url, payload)
return response.json()
except:
return []
def postProxy(self, url, payload, headers):
path = Path.cwd()
proxyUrl = self.config.get('proxy_url')
# print(data)
try:
response = requests.post(url,
data=payload,
headers=headers,
proxies={
"http": proxyUrl,
"https": proxyUrl,
},
verify=f'{path}/zyte-proxy-ca.crt'
)
return response.json()
except:
return []