Reputation: 32331
I have a String as below
<iframe class = 'sproutvideo-player' src = '//videos.sproutvideo.com/embed/1c9adbb11d18e3c994/a5fd279ead76557c' width = '630' height = '354' frameborder = '0' allowfullscreen > < /iframe>
I am trying to read the attribute src from it .
I have tried as below
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"));
could you please tell me how to read the src attribute ?
Upvotes: 0
Views: 73
Reputation: 3994
Here:
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");
Remember that select
method returns a list of all matching elements in the argument. For this purpose, I have used .first()
here.
Upvotes: 1
Reputation: 16498
change
Elements links = doc.select("src");
to
Elements links = doc.select("iframe");
Upvotes: 1