Python 处理文本是一项非常常见的功能,本文整理了几种读取不同格式文本的案例,建议收藏备用!
-
提取 PDF 内容
-
提取 Word 内容
-
提取 Web 网页内容
-
读取 CSV 数据
-
读取Json 数据
1. 提取PDF内容
# pip install PyPDF2 安装 PyPDF2
import PyPDF2
from PyPDF2 import PdfFileReader
# Creating a pdf file object.
pdf = open("test.pdf", "rb")
# Creating pdf reader object.
pdf_reader = PyPDF2.PdfFileReader(pdf)
# Checking total number of pages in a pdf file.
print("Total number of Pages:", pdf_reader.numPages)
# Creating a page object.
page = pdf_reader.getPage(200