【发布时间】: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