Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Frame;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintStream;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.Random;
- import javax.imageio.ImageIO;
- public class Scraper {
- public static void main(String[] args) {
- init();
- System.out.println("-=Jonalu's online alt database account scraper=-");
- System.out.println("loading...");
- Frame f = new Frame();
- ca = new CaptchaApplet();
- f.add(ca);
- f.setSize(150, 100);
- f.setVisible(true);
- f.setAlwaysOnTop(true);
- f.setBackground(Color.WHITE);
- BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
- ca.repaint();
- String uIn;
- System.out.println("type help for commands");
- try {
- while((uIn = stdIn.readLine()) != null) {
- command(uIn);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- exit();
- }
- private static void exit() {
- System.out.println("-=Exiting=-");
- System.exit(0);
- }
- private static void init() {
- scrapedUsernames = new ArrayList<String>();
- }
- private static void command(String uIn) {
- if(uIn.equalsIgnoreCase("help")) {
- showHelp();
- } else if(uIn.equalsIgnoreCase("save")) {
- save();
- } else if(uIn.toLowerCase().startsWith("scrape")) {
- scrapeCommand(uIn);
- } else if(uIn.toLowerCase().startsWith("setfile")) {
- setfile(uIn);
- } else if(uIn.equalsIgnoreCase("exit")) {
- exit();
- } else if(uIn.equalsIgnoreCase("abort")) {
- abortCommand(uIn);
- } else if(captchaImage != null) {
- captchaCode = uIn;
- }
- }
- private static void setfile(String uIn) {
- try {
- String[] as = uIn.split(" ");
- if(as.length == 2) {
- outputFile = new File(as[1]);
- if(outputFile.exists() && outputFile.isDirectory())
- System.out.println("That's a directory!");
- else if(!outputFile.exists() && !outputFile.createNewFile())
- System.out.println("Couldn't create file");
- else
- System.out.println("Output file set");
- } else {
- System.out.println("Syntax Error. Correct Usage: setfile <path>");
- }
- } catch(IOException ioe) {
- ioe.printStackTrace();
- }
- }
- private static void abortCommand(String uIn) {
- abortScraping();
- }
- private static void scrapeCommand(String uIn) {
- String[] as = uIn.split(" ");
- if(as.length == 2) {
- try {
- int i = Integer.parseInt(as[1]);
- scrape(i);
- } catch(Exception e) {
- System.out.println("Syntax Error. Correct Usage: scrape <count>");
- }
- } else {
- System.out.println("Syntax Error. Correct Usage: scrape <count>");
- }
- }
- private static Thread scrapeThread = null;
- private static void scrape(final int i) {
- System.out.println("Scraping "+i+ (i == 1 ? " username" : " usernames"));
- scrapeThread = new Thread() {
- public void run() {
- try {
- for(int i1 = 0; i1 < i; i1++) {
- String s = scrape();
- if(s == null) {
- if(i1 < i-1) {
- System.out.println("Waiting 2 minutes");
- Thread.sleep(1000L*60L*2L);
- }
- continue;
- }
- System.out.println(s);
- break;
- }
- } catch(IOException ioe) {
- ioe.printStackTrace();
- } catch (InterruptedException e) {
- }
- System.out.println("Scraping finished.");
- showTotalUsernames();
- }
- };
- scrapeThread.start();
- }
- private static void showTotalUsernames() {
- System.out.println("Total Usernames: "+scrapedUsernames.size());
- }
- private static void abortScraping() {
- if(scrapeThread != null && scrapeThread.isAlive()) {
- scrapeThread.interrupt();
- showTotalUsernames();
- } else {
- System.out.println("Not scraping.");
- }
- }
- private static void save() {
- try {
- if(outputFile == null || (!outputFile.exists() && !outputFile.mkdirs() && !outputFile.createNewFile())) {
- System.out.println("no output file set. use setfile <path>.");
- } else {
- BufferedReader br = new BufferedReader(new FileReader(outputFile));
- ArrayList<String> usernames = new ArrayList<String>();
- String s1;
- while((s1 = br.readLine()) != null) {
- usernames.add(s1);
- }
- br.close();
- for(String s : scrapedUsernames) {
- if(!usernames.contains(s))
- usernames.add(s);
- }
- PrintStream ps = new PrintStream(outputFile);
- for(String s : usernames) {
- ps.println(s);
- }
- ps.flush();
- ps.close();
- System.out.println("Successfully saved.");
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- private static void showHelp() {
- System.out.println("-=Help=-");
- System.out.println("scrape <count> - scrape accounts");
- System.out.println("abort - abort scraping accounts");
- System.out.println("save - save scraped accounts to file");
- System.out.println("setfile <path> - set output file path");
- System.out.println("help - show this help");
- System.out.println("exit - exit the scraper");
- }
- private static String scrape() throws IOException, InterruptedException {
- {
- String s = "http://alts.min.vc/?getalt";
- captchaImage = ImageIO.read(new URL(s));
- ca.repaint();
- System.out.println("enter the captcha code now.");
- while(captchaCode == null)
- Thread.sleep(2L);
- }
- String s = "http://alts.min.vc/?getalt&captcha="+captchaCode+"&client="+getRandomString(5, 7);
- captchaCode = null;
- captchaImage = null;
- ca.repaint();
- URL url = new URL(s);
- InputStreamReader isr = new InputStreamReader(url.openStream());
- BufferedReader br = new BufferedReader(isr);
- //String s1;
- /*ArrayList<String> file = new ArrayList<String>();
- String s1;
- while((s1 = br.readLine()) != null) {
- file.add(s1);
- System.out.println(s1);
- }
- if(true)
- return "";/**/
- String[] as;
- as = br.readLine().split(":");
- br.close();
- isr.close();
- if(as.length == 2) {
- if(!scrapedUsernames.contains(as[0])) {
- scrapedUsernames.add(as[0]);
- System.out.println("Scraped "+as[0]);
- }
- return null;
- } else if(as.length > 0) {
- return as[0];
- } else {
- return "invalid answer";
- }
- }
- private static File outputFile;
- private static ArrayList<String> scrapedUsernames;
- private static CaptchaApplet ca;
- private static Image captchaImage = null;
- private static String captchaCode = null;
- private static Random random = new Random();
- private static final char[] allowedClientChars = new char[26];
- static {
- for(int i = 0; i < 26; i++)
- allowedClientChars[i] = (char) ('a' + i);
- }
- private static String getRandomString(int minLength, int maxLength) {
- int length = random.nextInt(maxLength-minLength)+minLength;
- String s = "";
- for(int i = 0; i < length; i++)
- s += allowedClientChars[random.nextInt(allowedClientChars.length)];
- return s;
- }
- private static class CaptchaApplet extends Applet {
- private static final long serialVersionUID = 2701017711819916677L;
- public CaptchaApplet() {
- }
- public void paint(Graphics g) {
- if(captchaImage != null) {
- g.drawImage(captchaImage, 0, 0, this);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement