Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法从所有pdf';它保存在一个文件夹中_Python_Text Extraction - Fatal编程技术网

Python 无法从所有pdf';它保存在一个文件夹中

Python 无法从所有pdf';它保存在一个文件夹中,python,text-extraction,Python,Text Extraction,我有大约22个pdf文件保存在文件夹中。PDF是法文的,第一页只有一行文字,开头有日期。我试图从第一页的每一页提取日期,并将其放入数据框中。但是,当我运行代码时,它生成的日期值行数超过22行 这是我写的代码 chk_files = os.listdir("C:\\Users") new_pdf_files = [fil for fil in chk_files if ".pdf" in fil] for fil in new_pdf_files:

我有大约22个pdf文件保存在文件夹中。PDF是法文的,第一页只有一行文字,开头有日期。我试图从第一页的每一页提取日期,并将其放入数据框中。但是,当我运行代码时,它生成的日期值行数超过22行

这是我写的代码

chk_files = os.listdir("C:\\Users")
new_pdf_files = [fil for fil in chk_files if ".pdf" in fil]
for fil in new_pdf_files:
    object = PyPDF2.PdfFileReader(fil)
    NumPage = object.getNumPages()
    for i in range(0, NumPage):
        pdfFileObj = open(fil, 'rb')
        pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
        pageObj = pdfReader.getPage(0)
        s= (pageObj.extractText())
        partitioned_string = s.partition('B')
        partitioned_string[0]
        translator = google_translator()
        translate_text = translator.translate(partitioned_string[0],lang_src='fr', lang_tgt='en')  
        string_date= str(translate_text)
        upper_string_date=string_date.upper()
        dt = parse(upper_string_date)
        announement_date = print(dt.strftime('%d-%B-%Y').upper())
print(announement_date)

所有第一页都有一行这样的文本

“2021年5月24日第622102172号法律义务公告第1页关于召开会议/代表联合会的公告”,我试图从开头提取第一个日期

发出

2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日 2021年5月24日


接下来是196次,但应该是22次

添加您得到的示例输出,以查看并帮助您@Ank我已经添加了输出为什么要运行此循环:
对于范围内的i(0,NumPage):
似乎您得到了第0页,NumPage timesank感谢我在我犯错误的地方得到了它