我希望在没有硬编码的情况下获得HTML元素名称和属性名称(我不想使用documet.getElementsByTag("*")或document.select("*"))。
是否有机会使用Apache动态获取元素名称,如果可能的话,请提供任何示例示例。
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);
}发布于 2014-03-07 12:22:27
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这就是你想要的吗?
https://stackoverflow.com/questions/22248462
复制相似问题