我用python创建了一个脚本,使用requests
模块和PyPDF2
库来解析网站的pdf内容。我只对pdf文件第4页(表格内容)中Facility Name
下column A
的名称感兴趣。我的脚本可以从那个页面上抓取内容,但我找不到任何方法只能得到名字,其他什么也得不到。你知道吗
pdf file link that I've used within the script
这是桌子的样子
我只对列标题Facility Name
下的名称感兴趣。你知道吗
我试过:
import io
import PyPDF2
import requests
URL = 'https://www.cms.gov/Medicare/Provider-Enrollment-and-Certification/CertificationandComplianc/Downloads/SFFList.pdf'
res = requests.get(URL)
f = io.BytesIO(res.content)
reader = PyPDF2.PdfFileReader(f)
contents = reader.getPage(3).extractText()
print(contents)
我现在得到的结果是:
Facilit
y Name
Address
City
State
Zip
Phone
Number
Months as an
SFFWillows Center
320 North Crawford Street
Willows
CA95988530-934-2834
5Winter Park Care & Rehabilitation Center
2970 Scarlett Rd
Winter Park
FL32792407-671-8030
and so on -----
我希望有这样的输出:
Willows Center
Winter Park Care & Rehabilitation Center
Pinehill Nursing Center
River Brook Healthcare Center
如何从pdf文件中仅获取表中可用的名称?
不幸的是,PDF不是结构化文档,它只是放置在坐标上的字符串/图像,以使其看起来与创建时完全一致,而不管哪个程序渲染它。这意味着您不能像HTML那样简单地解析它,因为表不是在
<table>
元素下,而是分散在一个页面上。你知道吗请参见:
看看https://github.com/atlanhq/camelot,它可能会对你有所帮助
(这里最多有10页的表格,使用手册可能是一个更快的选择,除非你有很多这样的PDF。)
相关问题 更多 >
编程相关推荐