【问题标题】:searching html files in directories using python使用python在目录中搜索html文件
【发布时间】:2014-08-17 16:06:43
【问题描述】:

我有一个 html 解析器函数,它需要每个文件的绝对路径。

如何搜索目录并仅查找以 .html 结尾的文件,然后返回每个文件的绝对路径?

【问题讨论】:

  • 到目前为止你有什么?

标签: python html search path directory


【解决方案1】:

您是否考虑过使用 python os 模块?它有 listdir(path) 命令

os.listdir(path)
Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order. It does not include the special entries '.' and '..' even if they are present in the directory.

Availability: Unix, Windows. 

使用它来获取目录中的所有文件名,过滤掉非html文件,然后在目录的路径前面加上绝对路径。 https://docs.python.org/2/library/os.html

【讨论】:

    猜你喜欢
    • 2013-09-22
    • 2012-01-20
    • 2011-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    相关资源
    最近更新 更多