关于puppeteer一个很神奇的问题

我用puppeteer创建一个实例,什么都不做,然后自己手动打开网址https://menhu.pt.ouchn.cn/site/ouchnPc/index,输入用户名,密码,进行坐标验证。提示无法登录。
image

但是我自己打开谷歌浏览器,同样的操作,可以正常登录。

以下是我的排查方案:
一、魔法问题,关闭所有代理,所有魔法,试了一下不行。
二、缓存问题,我谷歌浏览器使用无痕模式,可以正常登录,但是puppeteer创建的谷歌实例还是不行。
三、puppeteer配置问题,我分别用puppeteer打开的浏览器,跟自己手动打开谷歌浏览器。打开登录页面,随便抓取一个请求,分析请求头,果然发现了不同
// puppeteer
fetch(“https://iam.pt.ouchn.cn/am/config/authInstance/enabledModules.do”, {
headers: {
accept: “/”,
“accept-language”: “zh-CN,zh;q=0.9”,
“sec-fetch-dest”: “empty”,
“sec-fetch-mode”: “cors”,
“sec-fetch-site”: “same-origin”,
“x-requested-with”: “XMLHttpRequest”,
cookie: “SESSION=79adccb1-8271-4a52-b3f2-32c8902a77a9; HWWAFSESID=9f788942c3d5a07f4a; HWWAFSESTIME=1716405094095; amlbcookie=01; AMAuthCookie=AQIC5wM2LY4SfczLAjKAo8G-pIw8E_h33XnGsv4hyuLWmGk.AAJTSQACMDEAAlNLABQtMTA4NDk2NDY3NDExOTk2OTYzMQ…”,
Referer:
https://iam.pt.ouchn.cn/am/UI/Login?realm=%2F&service=initService&goto=https%3A%2F%2Fiam.pt.ouchn.cn%2Fam%2Foauth2%2Fauthorize%3Fservice%3DinitService%26response_type%3Dcode%26client_id%3D345fcbaf076a4f8a%26scope%3Dall%26redirect_uri%3Dhttps%253A%252F%252Fmenhu.pt.ouchn.cn%252Fouchnapp%252Fwap%252Flogin%252Findex%26decision%3DAllow”,
“Referrer-Policy”: “same-origin”,
},
body: null,
method: “GET”,
});

//浏览器
fetch(“https://iam.pt.ouchn.cn/am/config/authInstance/enabledModules.do”, {
headers: {
accept: “/”,
“accept-language”: “zh-CN,zh;q=0.9”,
“sec-ch-ua”: ‘“Chromium”;v=“124”, “Google Chrome”;v=“124”, “Not-A.Brand”;v=“99”’,
“sec-ch-ua-mobile”: “?0”,
“sec-ch-ua-platform”: ‘“Windows”’,
“sec-fetch-dest”: “empty”,
“sec-fetch-mode”: “cors”,
“sec-fetch-site”: “same-origin”,
“x-requested-with”: “XMLHttpRequest”,
cookie: “SESSION=8ac39b71-04e3-4501-b236-bbcb133b1b51; HWWAFSESID=3116679648cbe37631; HWWAFSESTIME=1716405126065; amlbcookie=01; AMAuthCookie=AQIC5wM2LY4SfczpkEb9GIX959x5A1PQ2-c4SU6mrjun-sQ.AAJTSQACMDEAAlNLABMxMDQ3ODUzOTQwMTY0MTA0NjQ3”,
Referer:
https://iam.pt.ouchn.cn/am/UI/Login?realm=%2F&service=initService&goto=https%3A%2F%2Fiam.pt.ouchn.cn%2Fam%2Foauth2%2Fauthorize%3Fservice%3DinitService%26response_type%3Dcode%26client_id%3D345fcbaf076a4f8a%26scope%3Dall%26redirect_uri%3Dhttps%253A%252F%252Fmenhu.pt.ouchn.cn%252Fouchnapp%252Fwap%252Flogin%252Findex%26decision%3DAllow”,
“Referrer-Policy”: “same-origin”,
},
body: null,
method: “GET”,
});

我以为我找到原因了,高兴的修改了puppeteer的配置
await mainPage.setExtraHTTPHeaders({
“sec-ch-ua”: ‘“Chromium”;v=“124”, “Google Chrome”;v=“124”, “Not-A.Brand”;v=“99”’,
“sec-ch-ua-mobile”: “?0”,
“sec-ch-ua-platform”: ‘“Windows”’,
});
然后重新试了下,这时候两个请求参数一模一样,然后重新登录,还是不行。。。

有大佬能直到啥原因吗?
我愿意有偿200解决问题

3 个赞

手动设置了User-Agent,也还是不行
await mainPage.setUserAgent(
“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36”
);

屏幕大小也不设置是么……

Webdriver 之类的特征隐藏了吗
https://bot.sannysoft.com/
https://blog.csdn.net/shayuchaor/article/details/103145810

4 个赞

@Radisnt 不怎么会用这个论坛的回复

用puppeteer extra插件试试?

Radisnt
根据 Radisnt 大佬的回复,我已经解决了,根本原因是网站对 webdriver 特征进行了检测。
谢谢各位大佬!

:face_holding_back_tears:原来如此

举手之劳,何足挂齿

兄弟,你微信还是 base64 一下,毕竟 L 站 Google 搜索权重很高的。

学习了,我也有段时间没用puppeteer了。

谢谢!