Jsoup查看目录内容 [英] Jsoup view directory contents

查看:101
本文介绍了Jsoup查看目录内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

列出网站链接的代码,是否可以查看目录的目录内容,例如位置http://www.youtube.com/Songs的列表文件



Code that list links for the site, is it possible to view directory contents for the directory say for instance list files at location http://www.youtube.com/Songs

package Jsoup;

import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class LinkParser {

    public static void main(String[] args) throws IOException {
        
        String url = "http://www.youtube.com";

        Document document = Jsoup.connect(url).get();
        Elements links = document.select("a[href]");
        
        for (Element link : links) {
            
            System.out.println("link : " + link.attr("href"));
            System.out.println("text : " + link.text());
        }
    }
}







显示的代码来自计算机的目录内容,但不是来自远程机器的超文本传输​​协议,http






The code that displays directory content from computer but not from remote machine via hyper text transfer protocol, http

package Io;

import java.io.File; 

public class Directories {
    
}
 
class DirList { 
  public static void main(String args[]) { 
    String dirname = "/Games"; 
    File f1 = new File(dirname); 
 
    if (f1.isDirectory()) { 
      System.out.println("Directory of " + dirname); 
      String s[] = f1.list(); 
 
      for (int i=0; i < s.length; i++) { 
        File f = new File(dirname + "/" + s[i]); 
        if (f.isDirectory()) { 
          System.out.println(s[i] + " is a directory"); 
        } else { 
          System.out.println(s[i] + " is a file"); 
        } 
      } 
    } else { 
      System.out.println(dirname + " is not a directory"); 
    } 
  } 
}





我尝试了什么:



更改了网址,运行几个网站的代码仍然没有显示目录内容。有一个与java类似的应用程序,但它显示来自计算机的目录内容,而不是来自远程机器的http:



What I have tried:

changed the url , ran the code for several sites still doesnt display directory contents. There is a similar application with java but it displays directory contents from the computer and not from remote machine via http:

推荐答案

URL必须有一个斜杠以检索目录列表(例如http://www.example.com/sub/)。如果没有尾部斜杠,您将获得该目录的默认页面。对于主目录,通常是起始页面和子目录,它可能是默认页面或错误,具体取决于Web服务器配置。



但是生成目录列表必须在Web服务器上配置,并且通常被禁用导致错误响应。
The URL must have a trailing slash to retrieve directory listings (e.g. http://www.example.com/sub/). Without the trailing slash you will get the default page for that directory. For the main directory that is usually the start page and for sub directories it might be a default page or an error depending on the web server configuration.

But the generation of directory listings must be configured on the web server and is usually disabled resulting in an error response.


这篇关于Jsoup查看目录内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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