如何通过 html 文件的用户获取运行时输入以使用 Jsoup 进行解析?
How to take Runtime inputs via user of html file to parse using Jsoup?
就像下面的代码片段:
File input = new File("Example.html");
Document doc = Jsoup.parse(input, "UTF-8", "Example.html");
Elements links = doc.select("a[href]");
System.out.print("\nLinks: ");
我只想让用户输入他选择的文件名,而不是这个硬编码的 "Example.html"。
这样做:
public class Test {
public static void main(String[] args) {
String filename = args[0];
File input = new File(filename);
Document doc = Jsoup.parse(input, "UTF-8");
Elements links = doc.select("a[href]");
System.out.print("\nLinks: ");
}
}
然后,运行它,做
java myClassFile.class FileNameIWant.html
这就是 main
方法中的 String[] args
的用途。
就像下面的代码片段:
File input = new File("Example.html");
Document doc = Jsoup.parse(input, "UTF-8", "Example.html");
Elements links = doc.select("a[href]");
System.out.print("\nLinks: ");
我只想让用户输入他选择的文件名,而不是这个硬编码的 "Example.html"。
这样做:
public class Test {
public static void main(String[] args) {
String filename = args[0];
File input = new File(filename);
Document doc = Jsoup.parse(input, "UTF-8");
Elements links = doc.select("a[href]");
System.out.print("\nLinks: ");
}
}
然后,运行它,做
java myClassFile.class FileNameIWant.html
这就是 main
方法中的 String[] args
的用途。