【问题标题】:Using Puppeteer&Python on Node.JS to solve captchas在 Node.JS 上使用 Puppeteer Python 解决验证码
【发布时间】:2021-10-16 06:28:56
【问题描述】:

我正在使用 puppeteer 库来访问一些网站并从它们的 HTML 文件中提取数据。对于这种方式,我有一个 Python 脚本可以帮助我解决每个验证码(如果有)。

现在,为了运行 Python 脚本,我使用来自 npm 的 python-shell,并提交:

   

 let options = {
        mode: 'text',
        args: [captchas[0].sitekey],
        scriptPath: path.resolve('bypass'),
        pythonPath: '/usr/bin/python',
    }
    console.log(`options.scriptPath`, options.scriptPath)

    PythonShell.run(
        `bypass/bypass.py`,
        options,
        (err, [, captchaKey]) => {
            if (err) throw err
            let solutions = [
                {
                    _vendor: captchas[0]._vendor,
                    id: captchas[0].id,
                    text: captchaKey,
                    hasSolution: true,
                },
            ]
            resolve({ solutions })
        }
    )

我遇到了这个错误 -


    Solving captcha...
    options.scriptPath MY_PATH/backend/bypass
    file:///MY_PATH/backend/bypass/captchaBypasser.js:18
                (err, [, captchaKey]) => {
                ^
    
    TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))
        at file:///MY_PATH/backend/bypass/captchaBypasser.js:18
        at PythonShell._endCallback (/MY_PATH/backend/node_modules/python-shell/index.js:254:20)
        at terminateIfNeeded (/MY_PATH/backend/node_modules/python-shell/index.js:209:39)
        at ChildProcess.<anonymous> (/MY_PATH/backend/node_modules/python-shell/index.js:182:13)


我也尝试过使用 child_process 的 spawn,如下所示:


    const location = path.resolve('bypass/bypass.py')
    console.log(`python ${location} ${captchas[0].sitekey}`)

    const run = spawn('python', [location, captchas[0].sitekey])
    run.stdout.on('data', ([, captchaKey]) => {
        let solutions = [
            {
                _vendor: captchas[0]._vendor,
                id: captchas[0].id,
                text: captchaKey,
                hasSolution: true,
            },
        ]
        resolve({ solutions })
    })

它似乎只是压碎了,甚至没有结果。


所以我尝试了实际的命令行:


    python /MY_PATH/backend/bypass/bypass.py ae7317...TOKEN...d0dab8b75

顺便说一句 - 我也尝试过使用版本 3.10.0 的 python3

现在我遇到了这个错误:

 
      from hcapbypass import bypass
      File "/MY_PATH/backend/bypass/hcapbypass.py", line 35
        def N_Data(req) -> str:
                        ^

所以我尝试使用几周前发布的最新版 Python 3.10.0,结果如下:


    File "/MY_PATH/backend/bypass/bypass.py", line 4, in <module>
        captcha_solved = bypass(sys.argv[1], 'google.com', True)
    TypeError: bypass() missing 1 required positional argument: 's'


为了您的充分理解,这里是绕过和求解器代码:

bypass.py


    from hcapbypass import bypass
    import sys
    
    captcha_solved = bypass(sys.argv[1], 'google.com', True)
    print(captcha_solved)

hcapbypass Link to github

有人知道该怎么做吗? 非常感谢!!!

【问题讨论】:

    标签: javascript python node.js puppeteer captcha


    【解决方案1】:

    好的,我找到了解决方案:

    在 hcapbypass.py 文件中,没有显示 httpx 模块,所以我创建了一个包含 bin 和 lib 文件夹的环境来在本地安装它。

    此外,很少有函数有一个不存在的参数。

    当然,解构一个空/未定义的数组 - 会引发错误!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-15
      • 2022-07-14
      • 1970-01-01
      • 2022-12-15
      • 1970-01-01
      • 2022-12-23
      相关资源
      最近更新 更多