擅长:python、mysql、java
<p>下面是在PDF文件中搜索关键字的代码。你知道吗</p>
<pre><code>import PyPDF2
import re
object = PyPDF2.PdfFileReader("test.pdf")
numPages = object.getNumPages()
string = "US stock price"
for i in range(0, numPages):
pageObj = object.getPage(i)
print("this is page " + str(i))
txt = pageObj.extractText()
resSearch = re.search(string, txt)
print(resSearch)
</code></pre>