一种基于浏览器,绕过各种限制的调用网站后台 api 的方法

2023/4/22 crawler

# 通过 Chrome DevTools Protocol 在控制台执行 js

利用其实现 openai 的网页 api 反向代理

chatgpt_reverse_proxy (opens new window)

overview

await page.evaluate('''
    async () => {
        response = await fetch("https://chat.openai.com%s", {
            "headers": {
                "accept": "*/*",
                "authorization": "%s",
                "content-type": "application/json",
            },
            "referrer": "https://chat.openai.com/",
            "referrerPolicy": "same-origin",
            "body": %s,
            "method": "%s",
            "mode": "cors",
            "credentials": "include"
        });
        return {
            status: response.status,
            statusText: response.statusText,
            headers: response.headers,
            content: await response.text()
        }
    }
    ''' % (target_path, access_token, body, request.method.upper())
)