简体   繁体   中英

how to get next line of the specific text in python

I am reading all the text from pdf file, here I need to get the next line of specific text "Voltage on Manhole Cover Manhole Location Manhole Grade"

required output is: "No Roadway To Grade/Flush"

some text:

Manhole Available for Inspection Yes

Voltage on Manhole Cover Manhole Location Manhole Grade    
No Roadway To Grade/Flush
Manhole Cover Type Manhole Cover Size Number of Entrances 1
Single Action Solid 24\"
Manhole Length 2 ft
Manhole Width 2 ft
Depth Clearance (D/C) 3 ft
Ceiling to Surface (C/S) 6 inches
Manhole Content Secondary (Less than 4kV), Streetlight     
# of Primary Cables 0
Environmental Controls

For pdf you need to have PyPDF2 package. Create text file

pdfFileObj=PyPDF2.PdfReader('file_name.pdf')
whole_text=pdfFileObj.pages[0].extract_text()
text_file = open(r'file_name.txt', 'w')
text_file.write(whole_text)
text_file.close()

Then do this

f = open('file_name.txt', 'r')
for line in f:
     line = line.strip()      #strips first and last lines
     line = line.strip()      
     break;

print(line)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM