Java gets the collection of addresses of the images inside the HTML page code

Source: Internet
Author: User

Package com.blue.common.util;
Import java.util.ArrayList;
Import Java.util.HashSet;
Import java.util.List;
Import Java.util.Set;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern;


public class Getimagepathutil {

/**
* Get the address of the picture on the webpage
*/
public static set<string> Getimgstr (String htmlstr) {
Set<string> pics = new hashset<string> ();
String img = "";
Pattern P_image;
Matcher M_image;
String regex_img = "]*?> "; Image link Address
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;
}

}

Java gets the collection of addresses of the images inside the HTML page code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.