finding recaptcha callback

ⅰ亾dé卋堺 提交于 2021-01-28 05:22:36

问题


im trying to get data from this page

https://ahrefs.com/backlink-checker

its basically a website to check a domain rank and other status , when u enter a domain and click the check Check backlinks button it shows a google recaptcha

im using a captcha service to bypass this , problem is this site uses a callback on the captcha completion , when i recive the token from my api and put it in the #g-recaptcha-response i have to call the callback to move on there is no submit button

i used to find the callback in this object

___grecaptcha_cfg.clients[0].L.L.callback

and just call it like

page.evaluate(`___grecaptcha_cfg.clients[0].L.L.callback("${cap}")`)

but recently this obeject is nowhere to be found

and i get Evaluation failed: TypeError: Cannot read property 'L' of undefined

any idea?


回答1:


When I checked that url and when the captcha was there on the screen, then the object inside ___grecaptcha_cfg.clients[0] where callback was available was different i.e., L was not there on ___grecaptcha_cfg.clients[0], that's why you might have got the error. So thought of navigating to the callback object based on the type rather than directly accessing.

const client = ___grecaptcha_cfg.clients[0]
const keys = Object.keys(client)
const requiredKey = keys.find(key => client[key].constructor.name === "VK");

const requiredObj = client[requiredKey];

const callbackObjKey = Object.keys(requiredObj).find(key => requiredObj[key].callback);
requiredObj[callbackObjKey].callback("${cap}")

Hope this helps.

I have modified the code and used below approach to find the callback object, though this method is not so optimised but this is the way I could think to find out the callback method

const reduceObjectToArray = (obj) => Object.keys(obj).reduce(function (r, k) {
        return r.concat(k, obj[k]);
}, []);

const client = ___grecaptcha_cfg.clients[0]
let result = [];
result = reduceObjectToArray(client).filter(c => Object.prototype.toString.call(c) === "[object Object]")

result = result.flatMap(r => {
    return reduceObjectToArray(r)
})

result = result.filter(c => Object.prototype.toString.call(c) === "[object Object]")

const reqObj = result.find( r => r.callback)
reqObj.callback("${cap}")



来源:https://stackoverflow.com/questions/61759593/finding-recaptcha-callback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!