列出目录中的文件

时间:2016-12-18 14:53:47

标签: python

for file in os.listdir(".."):
    if file.endswith(".html"):
        print(file)
        with open(file, 'r') as f:
            for link in BeautifulSoup(f.read(), parse_only=SoupStrainer('a')):
                if link.has_attr('href'):
                    print(link['href'])

我有这个代码,我收到这样的错误

  

IOError:[Errno 2]没有这样的文件或目录:' quotes-.html'

我在Python DOC中读到The list is in arbitrary order, and does not include the special entries '.' and '..' even if they are present in the directory.

如何以其他方式实现这一点,请有人帮助我

0 个答案:

没有答案