Skip to content

Instantly share code, notes, and snippets.

@lzh77
Last active December 26, 2022 12:37
Show Gist options
  • Save lzh77/e52f41c06151964431386ec65903fb06 to your computer and use it in GitHub Desktop.
Save lzh77/e52f41c06151964431386ec65903fb06 to your computer and use it in GitHub Desktop.
Parse all vmess urls from one html file and write them into a text file. for batch importing to your client.
import java.io.*;
import java.util.HashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
private static final String PRE_PATH = "";
public static void main(String[] args) {
HashSet<String> result = new HashSet<>();
String a = getFileContent();
String reg = "\"vmess.*?\"";
Matcher m = Pattern.compile(reg, Pattern.DOTALL).matcher(a);
while (m.find()) {
String r = m.group(0);
result.add(r);
}
if (!result.isEmpty()) {
writeResults(result);
}
}
public static String getFileContent() {
File file = new File(PRE_PATH + "html.txt");
StringBuffer sb = new StringBuffer();
try {
Reader reader = new InputStreamReader(new FileInputStream(file), "UTF-8");
int len = 0;
for (char[] c = new char[1024]; (len = reader.read(c)) != -1; ) {
sb.append(c, 0, len);
}
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
public static void writeResults(HashSet<String> results) {
try {
File file = new File(PRE_PATH + "results.txt");
if (file.exists()) {
file.delete();
}
file.createNewFile();
OutputStream outputStream = new FileOutputStream(file);
PrintStream printStream = new PrintStream(outputStream);
for (String result : results) {
printStream.println(result.replaceAll("\"", ""));
}
printStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment