老师,帮忙看下这个报错是什么情况。
package crawler;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import javax.lang.model.util.Elements;
import java.io.IOException;
import java.net.URL;
public class CrawlerDemo {
// 爬虫
public static void main(String[] args) {
try {
//使用Jsoup获取玩野HTML源文件,转为Document对象
Document document = Jsoup.parse(new URL("https://www.163.com/dy/article/G8ELLBO30514R9OJ.html"),5000);
// System.out.println(document);
// 通过Document对象,获取需要的Element对象
//获取图片内容
// Elements element= (Elements) document.getElementsByAttributeValue("title","百度搜索");
// System.out.println(element);
// Elements headerEle= (Elements) document.select("post_side_mod");
Elements a= (Elements) document.select("description");
// System.out.println(headerEle);
System.out.println(a);
// 获取Element 对象的数据
}catch (IOException e){
e.printStackTrace();
}
}
}
输出:
"C:\Program Files\Java\jdk-12.0.1\bin\java.exe" --enable-preview "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3.2\lib\idea_rt.jar=54118:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\java\worksprce\Demo\out\production\Demo1;C:\java\worksprce\ Demo1\lib\jsoup-1.11.2.jar;C:\java\worksprce\ Demo1\lib\JsoupXpath-0.3.2.jar" crawler.CrawlerDemo
Exception in thread "main" java.lang.ClassCastException: class org.jsoup.select.Elements cannot be cast to class javax.lang.model.util.Elements (org.jsoup.select.Elements is in unnamed module of loader 'app'; javax.lang.model.util.Elements is in module java.compiler of loader 'platform')
at crawler.CrawlerDemo.main(CrawlerDemo.java:23)
Process finished with exit code 1