pdf转换成html python,在Python中将pdf转换为html

Python 2.6

我试图解析我的pdf文件,其中一种方法是将其转换为html并提取标题和段落。

所以,我尝试了pdf2htmlEX,它将我的pdf转换成html格式,而不干扰我的pdf格式。。。到目前为止,我还很高兴,但当我试图使用以下命令访问标题时:>> import subprocess

>> path = "/home/administrator/Documents/pdf_file.pdf"

>> subprocess.call(["pdf2htmlEX" , path])

但是当我打开我的html文件时,它给了我一些不必要的东西,更重要的是,我的文本没有标题标签,只有一堆div和span。在

^{pr2}$

我甚至试着用beauthoulsoup访问它>> from bs4 import BeautifulSoup as bs

>> soup = BeautifulSoup(f)

>> soup.find('div', attrs={'class': 'site-content'}).h1

它没有给我任何东西,因为没有标签。我也试过HTMLParser

从HTMLParser导入HTMLParser# create a subclass and override the handler methods

class myhtmlparser(HTMLParser):

def __init__(self):

self.reset()

self.NEWTAGS = []

你可能感兴趣的:(pdf转换成html,python)