Sunday, 3 September 2023

Unable to retrieve a token from API request

I'm trying to take this token from a chinese website as this image displays, using python requests lib: enter image description here

I'm trying to retrieve this guy "acw_sc__v2". I sucessfully retrieve the other tokens, but I can't find where or how this one is being generated, I appreciate if someone could find its origin and show me how you did it.

The website URL is: https://we.51job.com/

The API I found here, searching by "python developer": https://we.51job.com/pc/search?keyword=python%20developer&searchType=2&sortType=0&metro=

My code:

import requests
import json

session = requests.Session()
cookies = session.get("https://oauth.51job.com/ajax/get_token.php?fromdomain=51job_web").cookies

cookie_data = cookies.get_dict()
guid = cookie_data["guid"]
acw_tc = cookie_data["acw_tc"]

headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'en,en-US;q=0.9,fr-FR;q=0.8,fr;q=0.7,pt;q=0.6',
    'Connection': 'keep-alive',
    'From-Domain': '51job_web',
    'Referer': 'https://we.51job.com/pc/search?keyword=python developer&searchType=2&sortType=0&metro=',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
    'account-id': '',
    'partner': 'www_google_com',
    'property': json.dumps({
        "partner": "www_google_com",
        "webId": 2,
        "fromdomain": "51job_web",
        "frompageUrl": "https://we.51job.com/",
        "pageUrl": "https://we.51job.com/pc/search?keyword=python developer&searchType=2&sortType=0&metro=",
        "identityType": "",
        "userType": "",
        "isLogin": "是",
        "accountid": "",
        "keywordType": ""
    }),
    'sec-ch-ua': '"Chromium";v="116", "Not)A;Brand";v="24", "Google Chrome";v="116"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': 'Windows',
    'sign': '75f6fe150e9824fa27fe977fe3010da9925090e7af46e301a87fda31dca761c4',
    'user-token': '',
    'uuid': '95473941fbf1c03bfb07abf237130b54',
}

cookies = {
    "Cookie": f"partner=www_google_com; seo_refer_info_2023=%7B%22referUrl%22%3A%22https%3A%5C%2F%5C%2Fwww.google.com%5C%2F%22%2C%22referHost%22%3A%22www.google.com%22%2C%22landUrl%22%3A%22%5C%2Fdefault-e.php%22%2C%22landHost%22%3A%22www.51job.com%22%2C%22partner%22%3Anull%7D; privacy=1693088459; guid={guid}; sajssdk_2015_cross_new_user=1; Hm_lvt_1370a11171bd6f2d9b1fe98951541941=1693088465; nsearch=jobarea%3D%26%7C%26ord_field%3D%26%7C%26recentSearch0%3D%26%7C%26recentSearch1%3D%26%7C%26recentSearch2%3D%26%7C%26recentSearch3%3D%26%7C%26recentSearch4%3D%26%7C%26collapse_expansion%3D; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2295473941fbf1c03bfb07abf237130b54%22%2C%22first_id%22%3A%2218a33efb7c3ef7-0becd38ad9dd06-26031f51-2073600-18a33efb7c4dd2%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMThhMzNlZmI3YzNlZjctMGJlY2QzOGFkOWRkMDYtMjYwMzFmNTEtMjA3MzYwMC0xOGEzM2VmYjdjNGRkMiIsIiRpZGVudGl0eV9sb2dpbl9pZCI6Ijk1NDczOTQxZmJmMWMwM2JmYjA3YWJmMjM3MTMwYjU0In0%3D%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%24identity_login_id%22%2C%22value%22%3A%2295473941fbf1c03bfb07abf237130b54%22%7D%2C%22%24device_id%22%3A%2218a33efb7c3ef7-0becd38ad9dd06-26031f51-2073600-18a33efb7c4dd2%22%7D; acw_tc=ac11000116931044463076577e00e1a66347abd27c05bd50135d8dfd35ba92; Hm_lpvt_1370a11171bd6f2d9b1fe98951541941=1693104458; acw_sc__v2=64eab951c4ea897b8bc154952eb19ee3838665e1; JSESSIONID=E270CF9ADEC8A1DE358AC37EB01403C9; search=jobarea%7E%60%7C%21recentSearch0%7E%60000000%A1%FB%A1%FA000000%A1%FB%A1%FA0000%A1%FB%A1%FA00%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA9%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA0%A1%FB%A1%FApython+developer%A1%FB%A1%FA2%A1%FB%A1%FA1%7C%21recentSearch1%7E%60020000%A1%FB%A1%FA021000%A1%FB%A1%FA0000%A1%FB%A1%FA00%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA9%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA0%A1%FB%A1%FAGPT%A1%FB%A1%FA2%A1%FB%A1%FA1%7C%21recentSearch2%7E%60000000%A1%FB%A1%FA000000%A1%FB%A1%FA0000%A1%FB%A1%FA00%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA9%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA0%A1%FB%A1%FAdata+analyst%A1%FB%A1%FA2%A1%FB%A1%FA1%7C%21; ssxmod_itna=CqAx0DBD9Gu4zrD2lm3itGOmK4xormOlmpax0vei=NDpxBFP4oGQKcLoqASvbHUE3hxahRGS+4mPorBxGLDmKjQcfCPiiDC40rD74irDDxD3kx7PGmDimSjD7OCS9X5ycPDwDlKDgDQIdyxDaDGc7FAu7joasUl5DnpxkbY27D75Dux0HLjExwxDCCSExR29ma4i3AnczMx0OD0IGfxusDB+OngFFf/i=eGb0N7q4Nj+3kG0P5mh4N6biHGDxcY2DDXR3Cj4=HixPmYtDiOa2aYD; ssxmod_itna2=CqAx0DBD9Gu4zrD2lm3itGOmK4xormOlmpxn9Eei=eDloophDj+np1Ldidj93nDYuP4HB64HXQnF2dTi8MKYmy0ALjZ8Hioroi1yAADq+0PWq9UOIw883GxaK6x00K+Iroc0HsVN87q5dRMjnl2XXmD39F3ID1xvEQqA8QMdj7wIpnmT7eRKutmfnYuArqRprgiNi=koN2fbHIeboqleDKuDHD7=DeuDxD==; acw_tc={acw_tc}; acw_sc__v2=64eb709f5c1aa93d711318293708c7e47bee8bd2"

}

response = requests.get(
    'https://we.51job.com/api/job/search-pc?api_key=51job&timestamp=1693104486&keyword=python%20developer&searchType=2&function=&industry=&jobArea=000000&jobArea2=&landmark=&metro=&salary=&workYear=&degree=&companyType=&companySize=&jobType=&issueDate=&sortType=0&pageNum=1&requestId=&pageSize=20&source=1&accountId=&pageCode=sou%7Csou%7Csoulb',
    headers=headers, cookies=cookies)

# Debug information
print("Status Code:", response.status_code)
print("Response Text:", response.text)

try:
    print("JSON Response:", response.json())
except json.JSONDecodeError:
    print("Could not decode JSON.")

Btw, Idk if this is the only piece missing for the request to succeed, but apparently it is, whenever I change this guy "acw_sc__v2" with one more updated, this works.

I also realized all of them starts with 64+some numbers Very likely it is something encoded, but I have no idea, I tried to decode but didnt work.



from Unable to retrieve a token from API request

No comments:

Post a Comment