I am trying to do some web scraping from here but I am struggling to get the access token automaticaly. Everytime I do the web scraping, I need to manually update the Bearer token. Is there a way to do this automaticaly?
Let me show you how I do it manually:
JavaScript
x
28
28
1
url_WiZink = 'https://www.creditopessoal.wizink.pt/gravitee/gateway/api-chn-loans/v1/loans/quotation'
2
3
headers_WiZink = {'Accept': 'application/json',
4
'Accept-Encoding': 'gzip, deflate, br',
5
'Accept-Language': 'pt-PT',
6
'Authorization': 'Bearer de6ea490-381e-417f-ab77-3aad0d7eb63c',
7
'Connection': 'keep-alive',
8
'Content-Length': '266',
9
'Content-Type': 'application/json;charset=UTF-8',
10
'Host': 'www.creditopessoal.wizink.pt',
11
'Origin': 'https://www.wizink.pt',
12
'Referer': 'https://www.wizink.pt/',
13
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
14
'sec-ch-ua-mobile': '?0',
15
'Sec-Fetch-Dest': 'empty',
16
'Sec-Fetch-Mode': 'cors',
17
'Sec-Fetch-Site': 'same-site',
18
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
19
'X-Channel-Id': 'LOANSIMULATOR',
20
'X-Client-Id': 'simWzkPt',
21
'X-Country-Id': 'PRT',
22
'X-Device-UUID': 'd14e9b629804cbba1ac7c3e78ab39a56'}
23
24
25
payload_WiZink = {"productCode":"WZP01","fixedTermLoanId":84,"impositionAmount":{"amount":10000,"currency":"EUR"},"settlementDay":"5","dueOrAdvanceInterestIndicator":"3","nominalInterest":"8.0000000","feeRateId":"05","settlementFrequencyId":"0001","deprecationFrequencyId":"0001"}
26
27
response_WiZink = requests.post(url_WiZink, headers=headers_WiZink, json=payload_WiZink, verify=False).json()
28
Advertisement
Answer
For that website, you can get an access token by calling their oauth/token
endpoint:
JavaScript
1
10
10
1
import requests
2
3
access_token = requests.post(
4
'https://www.creditopessoal.wizink.pt/gravitee/gateway/api-chn-auth-server/v1/oauth/token',
5
headers={'Authorization': 'Basic c2ltV3prUHQ6YmllZTktZmR6dzAzLXBvZWpuY2Q='},
6
data={'grant_type': 'client_credentials'},
7
).json()['access_token']
8
9
print(access_token)
10