import org.jsoup.*;
import org.w3c.dom.Document;
public class jsoup {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String html = "<html><head><title>First parse</title></head>"
+ "<body><p id='xxx'>Parsed HTML into a doc.</p></body></html>";
Document doc = (Document)Jsoup.parse(html);
Element el = doc.getElementById("xxx");
}
}
当我运行上面的代码时,我收到一个
error:Element cannot be resolved to a type in line "Element el = doc.getElementById("xxx");"
你能帮我吗?
最佳答案
这只是一个编译错误。您需要导入Element
.
import org.jsoup.nodes.Element;
阅读Jsoup javadocs对于所有包和类。它们链接在 Jsoup home page 。另请注意,Jsoup 不使用 org.w3c.dom
中的 Document
。删除该行和不必要的强制转换。
关于java - 元素无法解析为类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7479447/