用Python绕过验证码

用Python绕过验证码,python,python-imaging-library,tesseract,captcha,Python,Python Imaging Library,Tesseract,Captcha,我正在使用Tesseract、PIL和ImageMagick工具绕过验证码 代码如下: import pytesseract import sys import argparse try: import Image except ImportError: from PIL import Image from subprocess import check_output def resolve(path): print("Resampling the Image")

我正在使用Tesseract、PIL和ImageMagick工具绕过验证码

代码如下:

import pytesseract
import sys
import argparse
try:
    import Image
except ImportError:
    from PIL import Image
from subprocess import check_output


def resolve(path):
    print("Resampling the Image")
    check_output(['convert', path, '-resample', '600', path])
    return pytesseract.image_to_string(Image.open(path))

argparser = argparse.ArgumentParser()
argparser.add_argument('/Users/rodrigopeniche/Documents/workspace/WebScraping/captcha.png',help = 'Captcha file path')
args = argparser.parse_args()
path = args.path
print('Resolving Captcha')
captcha_text = resolve(path)
print('Extracted Text', captcha_text)
首先,在命令行中执行时,是否仍可以执行此代码而不必传递文件位置

然后在执行时,我得到这个错误:

Traceback (most recent call last):
  File "/Users/rodrigopeniche/Documents/workspace/WebScraping/captchabypasser.py", line 20, in <module>
path = args.path
AttributeError: 'Namespace' object has no attribute 'path'
回溯(最近一次呼叫最后一次):
文件“/Users/rodrigopeniche/Documents/workspace/WebScraping/captchabasser.py”,第20行,在
path=args.path
AttributeError:“命名空间”对象没有属性“路径”

问题在于,您从未定义名为
path
的参数。将add_参数行更改为:

argparser.add_argument('path', help='Captcha file path')

#Or, if you want to make the command line parameter optional, give it a default

argparser.add_argument('path', default='/Users/rodrigopeniche/Documents/workspace/WebScraping/captcha.png', help='Captcha file path')
当然,如果您对解析命令行参数不感兴趣,可以手动设置路径