public class Test {
public static void Main (string[] args) {
String Source = "<p> Sdfasdfasdfsadfasdfasdfasdfasdfasdf</p>System.out.println (Getimgstr (source));
String htmlstr = "<p><video controls=\" Controls\ "durationtime=\" 72\ "filesize=\" 27117469\ "height=\" 200px\ " Poster=\ "https://xxxxxx/b439b0281450abce7f13b2920da04346.png\" src=\ "https://xxxxxxxxxx/ B439b0281450abce7f13b2920da04346.mp4\ "style=\" \ "> </video></p>";
System.out.println (Getvideostr (HTMLSTR));
}
public static set<string> Getimgstr (String htmlstr) {
Set<string> pics = new hashset<> ();
String img = "";
Pattern P_image;
Matcher M_image;
String regex_img = "]*?> ";
P_image = Pattern.compile (regex_img, pattern.case_insensitive);
M_image = P_image.matcher (HTMLSTR);
while (M_image.find ()) {
Get Data
img = M_image.group ();
Match src data in
Matcher m = pattern.compile ("src\\s*=\\s*\"? *?) (\ "|>|\\s+)"). Matcher (IMG);
while (M.find ()) {
Pics.add (M.group (1));
}
}
return pics;
}
public static map<string, string> getvideostr (String htmlstr) {
map<string, string> pics = new hashmap<string, string> ();
String regex_video= "<video.*poster\\s*=\\s* (. *?) [^>]*?src\\s*=\\s* (. *?) [^>]*?> ";
Pattern p = pattern.compile (regex_video,pattern.case_insensitive);
Matcher m = P.matcher (HTMLSTR);
String video= "";
map<string, string> map = new hashmap<string, string> ();
while (M.find ()) {
Video=m.group ();
Matcher Mposter = Pattern.compile ("poster\\s*=\\s*\"? *?) (\ "|>|\\s+)"). Matcher (video);
Matcher MSRC = Pattern.compile ("src\\s*=\\s*\"? *?) (\ "|>|\\s+)"). Matcher (video);
String poster = "";
String src= "";
while (Mposter.find ()) {
Poster=mposter.group (1);
}
while (Msrc.find ()) {
Src=msrc.group (1);
}
Map.put ("poster", poster);
Map.put ("src", SRC);
}
return map;
}
}
Java Regular Expressions extract attributes from tags (src connection address), etc.