通过 Python 循环浏览网络上的目录并显示其内容(文件和其他目录)

发布于 2024-09-03 02:58:22 字数 434 浏览 2 评论 0原文

同样,在 Python 中处理从源目录到目标目录的一组文件 我想知道是否可以创建一个函数,当给定一个 Web 目录时,它将列出该目录中的文件。就像...

files[]

for file in urllib.listdir(dir):
    if file.isdir:
        # handle this as directory
    else:
        # handle as file

我假设我需要使用 urllib 库,但至少我见过,似乎没有一种简单的方法可以做到这一点。

In the same vein as Process a set of files from a source directory to a destination directory in Python I'm wondering if it is possible to create a function that when given a web directory it will list out the files in said directory. Something like...

files[]

for file in urllib.listdir(dir):
    if file.isdir:
        # handle this as directory
    else:
        # handle as file

I assume I would need to use the urllib library, but there doesn't seem to be an easy way of doing this, that I've seen at least.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡淡绿茶香 2024-09-10 02:58:22

什么是网络目录?

网页有链接。带有链接的页面可能是也可能不是由网络服务器根据目录的内容生成的。

自动生成链接的示例可以在 此处 找到,并且可能是类似 mod_dir Web 服务器 Apache 中的配置。

wget 和curl 等工具的作用是获取一个页面并下载该页面上的所有链接(可能是递归的)。我认为这是你能实现的最好目标。我感觉关于 python +curl 的问题在 SO 中很丰富。

What is a web directory?

A web page has links. The page with the links may, or may not be, generated by the web server based on the contents of the directory.

An example of automatically generating links is found here, and is possibly the result of something like mod_dir configuration in the Web server, Apache.

What tools like wget, and curl, do, is take a page and download all links on that page, possibly recursively. I think that is the best you can achieve. And I have the feeling that questions about python + curl are abundant here in SO.

瑕疵 2024-09-10 02:58:22

您可能对这个概念感到困惑。目录是文件系统的概念。 URL没有目录的概念。它看起来类似于文件系统的路径名,通常映射到目录。但不需要文件系统支持它。

例如,在 Python 中处理从源目录到目标目录的一组文件可能会映射到目录

/htdocs/questions /2593399/

但更有可能它是从数据库查询生成的,并且不映射到文件系统中的任何内容。

You may got the concept confused. Directory is file system concept. URL do not have a concept of directory. It looks similar to the path name of a file system and often maps to a directory. But there is no requirement for it to be backed by a file system.

For example, Process a set of files from a source directory to a destination directory in Python may map to a directory

/htdocs/questions/2593399/

But more likely it is generated from a database query and does not map to anything in the file system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文