问题描述
列出网站链接的代码,是否可以查看目录的目录内容,例如位置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:
推荐答案
这篇关于Jsoup查看目录内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!