Java AESFast:好的-当我试图解析HTML文件时,它是什么意思?
我之所以这么做,是因为我正在努力学习如何解析Html文件 因此,当我尝试运行此代码时,从示例:Java AESFast:好的-当我试图解析HTML文件时,它是什么意思?,java,parsing,web-scraping,jsoup,aes,Java,Parsing,Web Scraping,Jsoup,Aes,我之所以这么做,是因为我正在努力学习如何解析Html文件 因此,当我尝试运行此代码时,从示例: import java.io.File; import java.io.IOException; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; public class Parse { public static void main(String[
import java.io.File;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class Parse {
public static void main(String[] args) {
//1
String HTMLSTring = "<!DOCTYPE html>"
+ "<html>"
+ "<head>"
+ "<title>JSoup Example</title>"
+ "</head>"
+ "<body>"
+ "<table><tr><td><h1>HelloWorld</h1></tr>"
+ "</table>"
+ "</body>"
+ "</html>";
Document html = Jsoup.parse(HTMLSTring);
String title = html.title();
String h1 = html.body().getElementsByTag("h1").text();
System.out.println("firts thing:");
System.out.println("Input HTML String to JSoup :" + HTMLSTring);
System.out.println("After parsing, Title : " + title);
System.out.println("Afte parsing, Heading : " + h1);
//2
Document doc;
try {
doc = Jsoup.connect("http://google.com/").get();
title = doc.title();
} catch (IOException e)
{
e.printStackTrace();
}
System.out.println("Second thing, reading html page from a URL document: ");
System.out.println("Jsoup Can read HTML page from URL, title : " + title);
//3
// JSoup Example 3 - Parsing an HTML file in Java //
//Document htmlFile = Jsoup.parse("login.html", "ISO-8859-1");
// wrong
Document htmlFile = null;
try {
htmlFile = Jsoup.parse(new File("login.html"), "ISO-8859-1");
} catch (IOException e)
{
e.printStackTrace();
} // right
title = htmlFile.title();
Element div = htmlFile.getElementById("login");
String cssClass = div.className();
// getting class form HTML element
System.out.println("Jsoup can also parse HTML file directly");
System.out.println("title : " + title);
System.out.println("class of div tag : " + cssClass);
}
}
编辑我重新下载了eclipse,现在输出正常,但我仍然不知道发生了什么