一种基于浏览器,绕过各种限制的调用网站后台 api 的方法
通过 Chrome DevTools Protocol 在控制台执行 js
利用其实现 openai 的网页 api 反向代理
python
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())
)