Last active
June 3, 2021 09:11
-
-
Save justudin/bab2f4b1f39f5a553c2a24b16346316c to your computer and use it in GitHub Desktop.
Get sbi won-idr current rate.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Coded by @justudin, 2021. | |
""" | |
import requests #pip install requests | |
import json | |
from bs4 import BeautifulSoup #pip install BeautifulSoup4 | |
SBI_COSMONEY = "https://www.sbicosmoney.com/" | |
SBI_COSMONEY_RATE = "https://www.sbicosmoney.com/calc/amount" | |
def get_SBI_rate(): | |
curSession = requests.Session() | |
page = curSession.get(SBI_COSMONEY) | |
soup = BeautifulSoup(page.content, 'html.parser') | |
_csrf = soup.find("meta",attrs={'name':'_csrf'}) | |
_csrf_header = soup.find("meta",attrs={'name':'_csrf_header'}) | |
body = {"countryId":"INDONESIA","currency":"IDR"} | |
headers = {} | |
headers["Content-type"] = 'application/json' | |
headers[_csrf_header["content"]] = _csrf["content"] | |
resp = curSession.post(SBI_COSMONEY_RATE, data=json.dumps(body), headers=headers) | |
data = resp.json() | |
return data["exchangeRate"] | |
if __name__ == '__main__': | |
rate = get_SBI_rate() | |
print(rate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment