Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
To show every urls of all images from a source code (html) file.
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class ImageFileUrlPrinter {
private static final String USER_ID = "999999"; // Target userID
private static final String CONDITION = "\" src=\"https://fanty-master-storage.s3.ap-northeast-1.amazonaws.com/user/" + USER_ID + "/post/";
public static void main(String[] args) {
// candfans.html is a html source code that you saved from a fully-generageted html of the target user's page.
File file = new File("candfans.html");
FileReader reader = null;
try {
reader = new FileReader(file);
BufferedReader br = new BufferedReader(reader);
for (String line = br.readLine(); line != null; line = br.readLine()) {
int start = 0;
int end = 0;
int jpeg = 0;
int jpg = 0;
int png = 0;
start = line.indexOf(CONDITION, start);
while (start >= 0) {
jpeg = line.indexOf(".jpeg", start);
if (jpeg > 0 && jpeg - start < 150) {
start = start + 7;
end = jpeg + 5;
System.out.println(line.substring(start, end));
}
jpg = line.indexOf(".jpg", start);
if (jpg > 0 && jpg - start < 150) {
start = start + 7;
end = jpg + 4;
System.out.println(line.substring(start, end));
}
png = line.indexOf(".png", start);
if (png > 0 && png - start < 150) {
start = start + 7;
end = png + 4;
System.out.println(line.substring(start, end));
}
start = end;
start = line.indexOf(CONDITION, start);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (Exception e) {
// do nothing
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment