简体   繁体   English

jsoup.Parse在iframe元素上不起作用

[英]jsoup.Parse not working on iframe element

I am trying to parse HTML file. 我正在尝试解析HTML文件。 The HTML includes iframe contents. HTML包含iframe内容。 But jsoup.parse() is working on all elements excepts iframe elements. 但是jsoup.parse()可以处理除iframe元素以外的所有元素。 Can anyone help me on this. 谁可以帮我这个事。 For example: 例如:

String html = "<iframe src='demo_iframe.htm' height='200' width='300'></iframe>";
String doc = Jsoup.parse(html).text();
System.out.println(doc);

The output should look like:

demo_iframe.htm height:200 width:200 demo_iframe.htm高度:200宽度:200

You have to select iframe element. 您必须选择iframe元素。 Here is solution 这是解决方案

String html = "<iframe src='demo_iframe.htm' height='200' width='300'></iframe>";
    Document doc = Jsoup.parse(html);
    Element iframe = doc.select("iframe").first();
    String iframeSrc = iframe.attr("src");
    String height = iframe.attr("height");
    String width = iframe.attr("width");
    System.out.println(iframeSrc + " height:" + height + " width:" + width);

Use selector-syntax to find elements 使用选择器语法查找元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM