我在使用pypdf时遇到了一个问题,当我查找一个特定单词在pdf文件中的次数时。在
在我的代码中,它发现一个单词的次数,但一页只有一次。所以最大值是页数。单词“The”的结果应该是700左右,但是只显示了30(页面的数量是30)。在import PyPDF3
import re
def read_pdf(file,string):
fils = file.split(".")
print(fils[1])
word = string
if fils[1] == "pdf":
pdfFileObj = open(file,"rb")
# open the pdf file
object = PyPDF3.PdfFileReader(file)
# get number of pages
NumPages = object.getNumPages()
# define keyterms
counter = 0
# extract text and do the search
for i in range(NumPages):
PageObj = object.getPage(i)
print("page " + str(i))
Text = PageObj.extractText()
#print(Text)
if word in Text:
print("The word is on this page")
counter += 1
print(word, "exists", counter, "times in the file")
你们能看看我做错了什么,帮我解决吗?在
谢谢:)