设为首页 收藏本站
查看: 724|回复: 0

[经验分享] python 搜索 PDF文件 内容

[复制链接]

尚未签到

发表于 2017-4-25 12:04:43 | 显示全部楼层 |阅读模式
我想做个小东东,需要读取pdf文件的文本内容,然后搜索某个关键词,返回这个关键词所在的页的页码,折腾我好几天了。首先看上了pypdf,啃了半天
洋文,发现这东西只能分割合并pdf文件,读取pdf文件的作者、标题等信息。然后又琢磨ReportLab,硬啃洋文,发现这东西主要是生成pdf文
件,好像也没有读取的方法(生成和读取难道是不相干的吗?),于是又在论坛一阵狂搜,发现有仁兄跟我类似的需要,高人指点他去研究poppler,我放
狗一搜,找到poppler的介绍页面,看到“The documentation is actually missing, help
wanted DSC0000.gif ”,心里就拔凉拔凉滴,俺是新手,有文档都要尚且研究半天,何况没文档啊,那是神人做的事啊,各位大侠,能否给指点一条明路,已经
折腾我好几天了,还没搞定?我只是想用python读取一下pdf文件的文本内容啊。
--~--~---------~--~----~------------~-------~--~----~
来自: `python-cn`:CPyUG ~ 华蟒用户组 | 发言:python-cn@...
退订: http://tinyurl.com/45a9tb /针对163/qq邮箱:http://tinyurl.com/4dg6hc
详情: http://groups.google.com/group/python-cn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
-~----------~----~----~----~------~----~------~--~---

1,poppler-utils 里边有 pdftotext、pdftohtml、pdfinfo 等工具用于提取 pdf 内容 。

下载了pypoppler-0.10.0.tar.gz,发现里面的文件没有setup.py,不能用python
setup.py install,而是linux下的install-sh的安装方式,我的是window xp系统,应该怎么安装呢?
安装 mingw、msys、python-dev,gtk-dev,pygtk-dev
不过应该还是 os.popen 调用 pdftotext.exe 简单

2,PDFminer比pdftoexe强太多了,正是我想要的。

----------------------------------------------------------------------------

最新免费的python开源项目

1、用python来做一个蜘蛛程序抓取网页,有了urllib库,真是太简单了。另外网页的解析也有相应的库sgmllib可以使用。不过还不知道python的sgmllib有没有类似 Jtidy 的规范html代码的功能,或者是有另外的库来干这事。

比较有名气的:

Harvest Man——http://code.google.com/p/harvestman-crawler/

HarvestMan is a modular, extensible and flexible web crawler program cum framework written in pure Python. HarvestMan can be used to download files from websites according to a number of customized rules and constraints. It can be used to find information from websites matching keywords or regular expressions.

The final goal of the project is to develop a full-fledged semantic personal data mining platform which can be used to retrieve information from the Internet in a highly customizable manner, so that one can fetch information from the web the way he wants it, when he wants it. For this, HarvestMan project will provide support for Web 2.0 and 3.0 technologies such as RSS, RDF, OWL etc. (这个目标还真是大啊,要是真的可以做到那就真是牛逼。)

另外,还有一些小的项目,用Google code或者 sourceforge.net搜索,就可以找到。

举个例子:

http://code.google.com/p/supercrawler/

2、对pdf文件的操作,C++,c#和java都有一些开源的类库可以使用。比如:pdflib,itext,pdfclown,pdfbox.

他们可以实现pdf文件的解析,并实现pdf与rtf html xml等格式之间的相互转换。

今天发现了一个可以操作pdf的python库: pdfminer.

http://code.google.com/p/pdfminerr/

不知道有没有其他的库。希望高手补充。

3、有了pdf的操作库,可以轻松实现对pdf文件内容的有目的的抽取。

这里有一个抽取文献的参考文献的例子:

pdf2ref

http://code.google.com/p/pdftoref/

This project aims to develop an efficient rule based extractor of entries of references, located in scientific articles in English language. The application takes a pdf file or a directory of pdf and then returns an html file, containing the list of all entries with their respective title. Moreover the title of the article cited is searched through Google Web Service to get the URL that identifying the article on the web. If the URL provides on the page a Bibtex entry, this will appear in the html output under the relative entries, stolen from some typical site like citeseer, ieeexlpore etc. The application does not make search over pdf file based on images.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-369110-1-1.html 上篇帖子: python Object And Class 下篇帖子: Python 学习系列(四)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表