问题:我本来是从《伤寒论医案集》pdf中识别文字的,但是这本书的pdf图片分辨率很低,看不清楚。即使使用百度高精度的ocr,识别错误率也比较高。后来找了最新版的书,在京东买了个电子版,然后准备把里面的病历一个个抄下来整理,但是时间长了,觉得还是太慢了。里面有500多份病历。.解决方案一:要从Windows系统上运行的软件中提取文本,可以使用uiautomation模块。这个模块是一个中国人利用业余时间开发的,结果发布在GitHub上。https://github.com/yinkaishen...uiautomation封装了微软UIAutomationAPI,支持Win32、MFC、WPF、ModernUI(MetroUI)、Qt、IE、Firefox(版本<=56或>=60、Firefox57)的自动化是第一个Rust开发版本,之前的Rust开发版本个人测试不支持),Chrome和基于Electron的应用(Chrome浏览器和Electron应用需要添加启动参数--force-renderer-accessibility来支持UIAutomation)然而我折腾了半天,还是获取不到京东阅读软件的内容,可能不是用上述技术开发的吧。importsysimporttimeimportuiautomationasautodefusage():auto.Logger.ColorfullyWrite("""usage-hshowcommandhelp-tdelaytime,默认3秒,在Value秒后开始枚举,这必须是一个整数,你可以延迟几秒,让一个窗口激活,这样自动化就可以枚举活动窗口-d枚举树depth,这个必须是整数,如果为null,则枚举整棵树-renumeratefromroot:Desktopwindow,如果为null,enumeratefromforegroundwindow-fenumeratefromfocused控件,如果为空,则从前台窗口-c枚举枚举cursor下的控件,如果depth<0,从其祖先枚举到depth-ashowancestors光标下的控件-nshowcontrolfullname,如果为空,在控制台显示控件名称的前30个字符,始终显示全名日志文件@AutomationLog.txt-p显示processidofcontrolsifUnicodeErrororLookupError打印时出现,尝试使用chcp更改控制台窗口的活动代码页或查看日志文件@AutomationLog.txtchcp,获取当前活动代码页chcp936,设置活动代码页为gbkchcp65001,设置活动代码页toutf-8examples:automation.py-t3automation.py-t3-r-d1-m-nautomation.py-c-t3""",writeToFile=False)defmain():importgetoptauto.Logger.Write('UIAutomation{}(Python{}.{}.{},{}位)\n'.format(auto.VERSION,sys.version_info.major,sys.version_info.minor,sys.version_info.micro,64ifsys.maxsize>0xFFFFFFFFelse32))选项,args=getopt.getopt(sys.argv[1:],'hrfcanpd:t:',['help','root','focus','cursor','ancestor','showAllName','depth=','time='])root=Falsefocus=Falsecursor=Falseancestor=Falseforeground=FalseshowAllName=Truedepth=4seconds=3showPid=Falsefor(o,v)in选项:ifoin('-h','-help'):usage()sys.exit(0)elifoin('-r','-root'):root=Trueforeground=Falseelifoin('-f','-focus'):focus=Trueforeground=Falseelifoin('-c','-cursor'):cursor=Trueforeground=Falseelifoin('-a','-ancestor'):ancestor=Trueforeground=Falseelifoin('-n','-showAllName'):showAllName=Trueelifoin('-p',):showPid=Trueelifoin('-d','-depth'):depth=int(v)elifoin('-t','-time'):seconds=int(v)ifseconds>0:auto.Logger.Write('请等待{0}秒\n\n'.format(seconds),writeToFile=False)time.sleep(seconds)auto.Logger.ColorfullyLog('开始,当前光标位置:{}'.format(auto.GetCursorPos()))control=Noneifroot:control=auto.GetRootControl()如果focus:control=auto.GetFocusedControl()如果cursor:control=auto.ControlFromCursor()如果depth<0:whiledepth<0和控制:control=control.GetParentControl()depth+=1depth=0xFFFFFFFF如果祖先:control=auto.ControlFromCursor()如果控制:auto.EnumAndLogControlAncestors(control,showAllName,showPid)else:auto.Logger.Write('IUIAutomation返回光标下的空元素\n',auto.ConsoleColor.Yellow)else:indent=0ifnotcontrol:control=auto.GetFocusedControl()controlList=[]whilecontrol:controlList.insert(0,control)control=control.GetParentControl()iflen(controlList)==1:control=controlList[0]else:control=controlList[1]ifforeground:indent=1auto.LogControl(controlList[0],0,showAllName,showPid)auto.EnumAndLogControl(控制,德pth,showAllName,showPid,startDepth=indent)auto.Logger.Log('Ends\n')if__name__=='__main__':main()UIAutomation2.0.16(Python3.6.13,64位)请等待3seconds2022-01-2811:54:57.432test2.py[77]main->开始,当前光标位置:(683,479)ControlType:WindowControlClassName:CAswerWndAutomationId:Rect:(0,0,1366,728)[1366x728]名称:'京东阅读'句柄:0x51326(332582)深度:0SupportedPattern:LegacyIAccessiblePatternTransformPatternWindowPatternControlType:WindowControlClassName:CReadWndAutomationId:Rect:(2,92,1364,726)[1362x634]NameFangMedicalCaseCollection'Handle:0x40F3C(266044)Depth:1SupportedPattern:LegacyIAccessiblePatternWindowPattern2022-01-2811:54:57.725test2.py[112]main->EndsProcessfinishedwithexitcode0使用里面的示例代码获取到各种控件以及notepad.exe的值,但是在京东阅读软件中只能识别其标题,无法获取里面的内容.如果谁能用这个方法得到,请留言告诉我哈。方案二:没办法,我不想做了,只能试试其他的方法。参考方法:https://jingyan.baidu.com/art...此方法是将电子书转为图片格式的pdf。之前的文章可以把图片pdf转成文字,所以我觉得这个方法是可行的。这种方法的思路是用录屏软件对电子书进行截图,保存图片,然后不断重复这个过程,得到整本书的截图。1.录屏软件很多。我在参考文档中也选择了SnagIt。该软件有绿色版。下载地址为:http://www.downxia.com/downin...解压后如下图:打开后界面如下,选择Capture->share->file然后选择Properties,和“属性”,并进行以下设置。然后下图所示界面中三个箭头所指的位置要设置成下图一样,这样图片就可以直接保存为文件,否则不会直接保存,而是打开在Snagit编辑器中。设置好后,可以先尝试截图,看能否保存图片文件。以下是软件自动保存的文件格式。2、重复步骤1,手动做太慢,可以用TinyTask软件反复做。绿色免费的TinyTask下载地址:https://www.greenxf.com/soft/...打开后界面如下,非常简单:点击Rec即可开始记录你在电脑上的操作。启动后,按钮变为红色,同时上面记录了您的操作时间。然后开始使用Snagit进行截图和翻页。操作完成后,您需要停止录制。您可以使用默认的快捷键ctr+shift+alt+r来停止。然后需要设置重复执行的次数,点击prefs,等待完成即可。3.识别图片中的文字这里可以使用我们之前的文章。https://segmentfault.com/a/11…