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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| async def handle_request(request, container): if 'x-api-key' in request.headers: container['x_api_key'] = request.headers['x-api-key']
if 'authorization' in request.headers: container['authorization'] = request.headers['authorization']
async def login_and_get_tokens(email, password): container = {}
async with async_playwright() as p: browser = await p.chromium.launch(headless=False) page = await browser.new_page()
page.on("request", lambda request: handle_request(request, container)) await page.goto("https://apply.commonapp.org/login") await page.fill('input[name="email"]', email) await page.fill('input[name="password"]', password) await page.click('button[type="submit"]') await page.wait_for_load_state("networkidle")
await browser.close() return container.get('authorization'), container.get('x_api_key')
def fetch_requirements(headers): url = 'https://api24.commonapp.org/datacatalog/members/requirements' response = requests.get(url, headers=headers) response.raise_for_status() return response.json()
async def main(): email = 'xxx' password = 'xxx' authorization, x_api_key = await login_and_get_tokens(email, password) print(authorization) print(x_api_key) if not any([authorization, x_api_key]): print("Failed to retrieve authorization.") return
headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Origin': 'https://apply.commonapp.org', 'Referer': 'https://apply.commonapp.org/', 'content-type': 'application/json', 'x-api-key': x_api_key, 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'Authorization': authorization }
requirements_data = fetch_requirements(headers)
|