我正在拍摄一个图像,通过pytesseract运行它来获得一个文本列表,并将该列表保存为一个变量:
img = Image.open(path_to_some_image)
imgtxt = pytesseract.image_to_string(img)
print(imgtxt)
>> Some text here
keyword
Random strings
Random chars
我的挑战是在没有定义它的情况下获取keyword
,因为它会根据程序运行的时间而变化。我发现keyword
总是跟在Some text here
后面,其中Some
和here
总是恒定的,并且text
在两个单词之间波动,所以我在here
处分割输出。现在,我得到以下信息:
print(imgtxt.split("here",1)[1])
>> keyword
Random strings
Random chars
这将删除keyword
之前的所有内容,而不定义它,但现在我想删除之后的所有内容。那么,我的问题是,我怎样才能去掉Random strings
和Random chars
,而不把keyword
变成一个变量呢?你知道吗
您可以再拆分一次,但这次得到第一项:
为我工作:
相关问题 更多 >
编程相关推荐