Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get src/url from <iframe> using java

Tags:

java

html

 String str = " <iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/UMUeWqnwmjs\" frameborder=\"0\" allowfullscreen></iframe>";

How to take the Src from this tag?

like image 864
AMU Avatar asked Mar 09 '26 11:03

AMU


1 Answers

In such simple case you can use regexp (normally you should not use it for parsing html). The code below will look for src and retrieve it:

Matcher matcher = Pattern.compile("src=\"([^\"]+)\"").matcher(str);
matcher.find();
String src = matcher.group(1);

src will contain your src from iframe.

like image 98
Krzysztof Krasoń Avatar answered Mar 10 '26 23:03

Krzysztof Krasoń



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!