循环通过Web上的目录,并通过Python显示其内容(文件和其他目录) [英] Looping through a directory on the web and displaying its contents (files and other directories) via Python

查看:290
本文介绍了循环通过Web上的目录,并通过Python显示其内容(文件和其他目录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将一组文件从源目录处理到Python中的目标目录我想知道是否可以创建一个函数,当给定一个Web目录时,它将列出文件中的文件说目录一些类似...

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

我假设我需要使用urllib库,但似乎并没有一个简单的方法,至少我已经看到了。

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服务器基于目录的内容生成的。

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.

发现自动生成链接的示例 here ,可能是类似 mod_dir 配置的结果在Web服务器中,Apache。

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.

像wget和curl这样做的工具是一个页面,并可以递归地下载该页面上的所有链接。我认为这是你可以实现的最好的。我有这样的感觉,在这里,关于python + curl的问题在这里很丰富。

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.

这篇关于循环通过Web上的目录,并通过Python显示其内容(文件和其他目录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆