我有一个字符串,如下所示
<iframe class = 'sproutvideo-player' src = '//videos.sproutvideo.com/embed/1c9adbb11d18e3c994/a5fd279ead76557c' width = '630' height = '354' frameborder = '0' allowfullscreen > < /iframe>
我正在尝试从中读取属性src。
我试过如下
String html = "<iframe class = 'sproutvideo-player' src = '//videos.sproutvideo.com/embed/1c9adbb11d18e3c994/a5fd279ead76557c' width = '630' height = '354' frameborder = '0' allowfullscreen > < /iframe>";
Document doc = Jsoup.parse(html);
Elements links = doc.select("src");
System.out.println(links.attr("src"));
你能告诉我如何阅读src属性吗?
答案 0 :(得分:1)
下面:
String html = "<iframe class = 'sproutvideo-player' src = '//videos.sproutvideo.com/embed/1c9adbb11d18e3c994/a5fd279ead76557c' width = '630' height = '354' frameborder = '0' allowfullscreen > < /iframe>";
Document doc = Jsoup.parse(html);
Element link = doc.select("iframe").first();
String linkHref = link.attr("src");
请记住,select
方法返回参数中所有匹配元素的列表。为此,我在这里使用了.first()
。
答案 1 :(得分:1)
更改
Elements links = doc.select("src");
到
Elements links = doc.select("iframe");