我遇到一种情况,我需要抓取一组仅包含一些 xml 数据的网页,并且我想获取特定元素的属性。我怎样才能在java中做到这一点?
比如说,xml结构是
<page>
<student id=2406>
.
.
</student>
.
.
.
</page>
我需要抓取很多页面,所以请推荐一个快速的抓取工具
编辑: 我看过一些与此相关的页面,但没有找到公平的答案。任何代码也将不胜感激
最佳答案
Jsoup 将是一个很好的爬虫。您可以使用它执行以下操作:
String xml = "this would be your xml";
Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
for (Element e : doc.select("tag")) {
System.out.println(e); //this will print the node with "tag"
}
要抓取网页,请使用以下代码:
Document doc = Jsoup.connect("url").get();
关于java - java中的网络爬行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33674254/