Home > other >  Python is a small white questions about the PDF into excel
Python is a small white questions about the PDF into excel

Time:11-23

The import pdfplumber
The from openpyxl import Workbook
Wb=Workbook ()
Ws=wb. Active
Path="c: \ Users \ NING MEI \ Desktop \ filename PDF"
PDF=pdfplumber. Open (path)
Print (' \ n ')
Print (' started to read the data)
Print (' \ n ')
Print (PDF) pages [1]. Extract_tables () [0] [0])
Ws. Append (PDF) pages [1]. The extract_tables () [0] [0])
For page in PDF. Pages:
# print (page. Extract_text ())
For the table in page. Extract_tables () :
# print (table)
For a row in the table:
If "serial number" not in a row:
# print (type (row))
Rowlist=STR (row). Replace ("/", "",.) replace ("]", ""). The replace (" '"," "). The replace (" \ \ n ", ""). The split ()", "
Print (rowlist)
Ws. Append (rowlist)
Print (" -- -- -- -- -- -- -- -- -- -- line -- -- -- -- -- -- -- -- -- -- ')
PDF. The close ()
# of Excel table
Wb. Save (' filename. XLSX)
Print (' \ n ')
Print (' write excel success ')
Print (' save location:)
Print (' filename. XLSX)
Print (' \ n ')

An error
SyntaxError: (unicode error) 'unicodeescape' codec can 't decode bytes in position 2-3: truncated \ UXXXXXXXX escape

What reason is this is the great god?

CodePudding user response:

In the wrong?


PDF=pdfplumber. Open (path) if is this line,
The path="c: \ Users \ NING MEI \ Desktop \ filename PDF"
Change path="c:/Users/NING MEI/Desktop/filename. PDF"
Try

  • Related