0

我正在努力获得1a。每个 10-K 文件中的风险因素部分。我已经下载了文件并将它们保存为txt。文件。

```'/content/drive/My Drive/Colab Notebooks/10/BKR/1.txt'
'/content/drive/My Drive/Colab Notebooks/10/BKR/2.txt'```

因此,文件夹 10 包含几个子文件夹(如 10),每个子文件夹(如 BKR)包含几个 10-K 作为 txt 文件。

我尝试了下面的代码来获取 1a.Risk Factors 部分,但它失败了。如果你能分享你的意见,我会很高兴。

```import re
import os, os.path

PATH = '/content/drive/My Drive/Colab Notebooks/10/BKR'

conclusions = []
for file in os.listdir(path):
    with open(os.path.join(PATH, file)) as f:
        data = f.read()

    conclusion = re.search('1a: (.*?)([A-Z]{2,})', data).group(1)
    conclusions.append(conclusion)```

我得到的错误信息:

```

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

NotADirectoryError                        Traceback (most recent call last)

<ipython-input-12-051ca10fbeb3> in <module>()
      5 
      6 conclusions = []
----> 7 for file in os.listdir(path):
      8     with open(os.path.join(PATH, file)) as f:
      9         data = f.read()

NotADirectoryError: [Errno 20] Not a directory: '/content/drive/My Drive/Colab Notebooks/10/APA/1.txt

'```

4

0 回答 0