我想要获取 HTML 元素名称和属性名称(我不想使用 documet.getElementsByTag("*")
或 document.select("*")
)无需硬编码。
是否有机会使用 Apache Tika 动态获取 HTML 元素名称,如果可能,请为我提供任何示例?
Document doc=Jsoup.connect("http://seenyc.co/").get();
Elements elements=doc.getAllElements();
for(Element ele:elements){
String s=ele.tagName();
Attributes n=ele.attributes();
System.out.println(s);
System.out.println(n);
}
最佳答案
HashSet<String> allTags=new HashSet<String>();
Document doc=Jsoup.connect("http://seenyc.co/").get();
Elements elements=doc.getAllElements();
for(Element ele:elements){
String s=ele.tagName();
Attributes n=ele.attributes();
allTags.add(s);
}
// here your hashset will have all distinct tag names from website
这是你想要的吗?
关于java - 如何从网站 url 获取 html 元素名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22248462/