Last active
May 1, 2022 08:28
-
-
Save x5gtrn/2e779c51f7e38705c41064da59b4b727 to your computer and use it in GitHub Desktop.
To show every urls of all images from a source code (html) file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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