Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. public static void findURLs(File file) {
  2.         try {
  3.             BufferedReader br = new BufferedReader(new FileReader(file));
  4.             String line = "";
  5.             Pattern pattern = Pattern.compile("(?i)href=\".+\"");
  6.            
  7.             while ((line = br.readLine()) != null) {
  8.                 Matcher m = pattern.matcher(line);
  9.                 while (m.find()) {
  10.                     String[] urls = m.group().split("(?i)\\s+");
  11.                     for (String s : urls) {
  12.                         if (s.matches("(?i)href=\".+\"")) {
  13.                             String[] cleaned = s.split("(?i)href=");
  14.                             for (String str : cleaned) {
  15.                                 if (!str.isEmpty())
  16.                                     System.out.println(str.substring(1, str.length()-1));
  17.                             }
  18.                         }
  19.                     }
  20.                 }
  21.             }
  22.            
  23.         } catch (FileNotFoundException e) {
  24.             e.printStackTrace();
  25.         } catch (IOException e) {
  26.             e.printStackTrace();
  27.         }
  28.     }
Add Comment
Please, Sign In to add comment