Advertisement
msatskevich

Untitled

Jan 29th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.86 KB | None | 0 0
  1. package mskins.promo;
  2.  
  3. import org.openqa.selenium.By;
  4. import org.openqa.selenium.StaleElementReferenceException;
  5. import org.openqa.selenium.TimeoutException;
  6. import org.openqa.selenium.WebDriver;
  7. import org.openqa.selenium.WebElement;
  8. import org.openqa.selenium.firefox.FirefoxDriver;
  9. import org.openqa.selenium.htmlunit.HtmlUnitDriver;
  10. import org.openqa.selenium.ie.InternetExplorerDriver;
  11. import org.openqa.selenium.support.ui.ExpectedConditions;
  12. import org.openqa.selenium.support.ui.WebDriverWait;
  13.  
  14. import com.gargoylesoftware.htmlunit.BrowserVersion;
  15.  
  16. import java.util.List;
  17. import java.util.Vector;
  18. import java.io.BufferedReader;
  19. import java.io.DataInputStream;
  20. import java.io.FileNotFoundException;
  21. import java.io.FileReader;
  22. import java.io.IOException;
  23. import java.io.InputStreamReader;
  24. import java.io.Reader;
  25. import java.time.Duration;
  26.  
  27. import org.json.simple.JSONArray;
  28. import org.json.simple.JSONObject;
  29. import org.json.simple.parser.JSONParser;
  30. import org.json.simple.parser.ParseException;
  31.  
  32. class User {
  33.    
  34.     public String username;
  35.     public String password;
  36.    
  37. }
  38.  
  39. class CreateBrowser extends Thread {
  40.    
  41.     public WebDriver[] browsers;
  42.     public int index;
  43.    
  44.     public CreateBrowser(WebDriver[] _browsers, int _index) {
  45.         browsers = _browsers;
  46.         index = _index;
  47.     }
  48.    
  49.     public void run() {
  50.         //WebDriver browser = new FirefoxDriver();
  51.         WebDriver browser = new HtmlUnitDriver(BrowserVersion.INTERNET_EXPLORER_11);
  52.         ((HtmlUnitDriver)browser).setJavascriptEnabled(true);
  53.         //browser.manage().window().maximize();
  54.         synchronized(browsers) {
  55.             browsers[index] = browser;
  56.         }
  57.     }
  58.    
  59. }
  60.  
  61.  
  62. class Authorize extends Thread {
  63.    
  64.     public WebDriver[] browsers;
  65.     public User[] users;
  66.     public int index;
  67.    
  68.     public Authorize(WebDriver[] _browsers, User[] _users, int _index) {
  69.         browsers = _browsers;
  70.         users = _users;
  71.         index = _index;
  72.     }
  73.    
  74.     public void run() {
  75.         WebDriver browser;
  76.         synchronized (browsers) {
  77.             browser = browsers[index];
  78.         }
  79.         boolean fl = true;
  80.        
  81.         synchronized (App.mt) {
  82.             browser.get("https://meowskins.cc/oauth/steam/redirect");
  83.            
  84.             WebElement username = browser.findElement(By.xpath("//input[@name=\"username\"]"));
  85.             WebElement password = browser.findElement(By.xpath("//input[@name=\"password\"]"));
  86.            
  87.             username.sendKeys(users[index].username);
  88.             password.sendKeys(users[index].password);
  89.            
  90.             username.submit();
  91.            
  92.             try {
  93.                 App.wait(browser, "//input[@class=\"authcode_entry_input authcode_placeholder\"]", 5);
  94.             }
  95.             catch (TimeoutException e) {
  96.                 fl = false;
  97.             }
  98.            
  99.             if (fl) {
  100.                 try {
  101.                     Thread.sleep(3000);
  102.                 } catch (InterruptedException e) {
  103.                     e.printStackTrace();
  104.                 }
  105.                
  106.                 try {
  107.                     Runtime.getRuntime().exec("mail.exe");
  108.                 } catch (IOException e) {
  109.                     e.printStackTrace();
  110.                 }
  111.                
  112.                 try {
  113.                     Thread.sleep(7000);
  114.                 } catch (InterruptedException e) {
  115.                     e.printStackTrace();
  116.                 }  
  117.                
  118.             }
  119.            
  120.         }
  121.        
  122.         if (fl) {
  123.             String guard = "";
  124.            
  125.             try {
  126.                 BufferedReader reader = new BufferedReader(new FileReader("mail.txt"));
  127.                 guard = reader.readLine();
  128.                 reader.close();
  129.             } catch (IOException e) {
  130.                 e.printStackTrace();
  131.             }
  132.            
  133.             WebElement guardinp =
  134.                     browser.findElement(By.xpath("//input[@class=\"authcode_entry_input authcode_placeholder\"]"));
  135.            
  136.             guardinp.sendKeys(guard);
  137.             guardinp.submit();
  138.            
  139.             App.wait(browser, "//*[@id=\"success_continue_btn\"]", 100);
  140.             WebElement authButton = browser.findElement(By.xpath("//*[@id=\"success_continue_btn\"]"));
  141.             authButton.click();
  142.            
  143.         }
  144.         else {
  145.             browser.get("https://meowskins.cc/oauth/steam/redirect");
  146.             App.wait(browser, "//input[@class=\"btn_green_white_innerfade\"]", 100);
  147.             WebElement button = browser.findElement(By.xpath("//input[@class=\"btn_green_white_innerfade\"]"));
  148.             button.click();
  149.         }
  150.        
  151.         try {
  152.             Thread.sleep(10000);
  153.         } catch (InterruptedException e) {
  154.             e.printStackTrace();
  155.         }
  156.         browser.get("https://meowskins.cc/");
  157.         System.out.println("I'm here.");
  158.        
  159.         App.wait(browser, "//div[@class=\"mini-profile-ava\"]//img", 100);
  160.         WebElement ava = browser.findElement(By.xpath("//div[@class=\"mini-profile-ava\"]//img"));
  161.         ava.click();
  162.        
  163.         App.wait(browser, "//input[@data-v-e6fade42]", 100);
  164.        
  165.     }
  166.    
  167. }
  168.  
  169.  
  170. class InputCode extends Thread {
  171.    
  172.     WebDriver[] browsers;
  173.     int index;
  174.     String code;
  175.    
  176.     public InputCode(WebDriver[] _browsers, int _index, String _code) {
  177.         browsers = _browsers;
  178.         index = _index;
  179.         code = _code;
  180.     }
  181.    
  182.     public void run() {
  183.         WebDriver browser = browsers[index];
  184.        
  185.         App.wait(browser, "//input[@data-v-e6fade42]", 100);
  186.         WebElement form = browser.findElement(By.xpath("//input[@data-v-e6fade42]"));
  187.        
  188.         //form.clear();
  189.         form.sendKeys(code);
  190.         form.submit();
  191.        
  192.         /* while (true) {
  193.             App.wait(browser, "//input[@data-v-e6fade42]", 100);
  194.             WebElement form = browser.findElement(By.xpath("//input[@data-v-e6fade42]"));
  195.            
  196.             form.clear();
  197.             form.sendKeys(code);
  198.             form.submit();
  199.            
  200.             App.wait(browser, "//div[@class=\"noty_body\"]", 100);
  201.             List <WebElement> errors = browser.findElements(By.xpath("//div[@class=\"noty_body\"]"));
  202.            
  203.             boolean fl = true;
  204.            
  205.             for (int i = 0; i < errors.size(); i++) {
  206.                 try {
  207.                     if (!errors.get(i).getText().contains("Предупреждение")) {
  208.                         fl = false;
  209.                         break;
  210.                     }
  211.                 }
  212.                 catch (StaleElementReferenceException e) {}
  213.             }
  214.            
  215.             if (!fl)
  216.                 break;
  217.            
  218.             try {
  219.                 Thread.sleep(1000);
  220.             } catch (InterruptedException e) {
  221.                 e.printStackTrace();
  222.             }
  223.            
  224.         } */
  225.        
  226.         System.out.println("kk");
  227.        
  228.     }
  229.    
  230. }
  231.  
  232.  
  233. public class App  {
  234.    
  235.     public static Object mt;
  236.    
  237.     public static void wait(WebDriver browser, String xpath, int t) {
  238.         WebDriverWait waiter = new WebDriverWait(browser, t);
  239.         waiter.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));
  240.     }
  241.    
  242.     public static User[] read() throws FileNotFoundException, IOException, ParseException {
  243.         JSONParser parser = new JSONParser();
  244.         JSONArray all = (JSONArray)parser.parse(new FileReader("data.json"));
  245.        
  246.         User[] ans = new User[all.size()];
  247.        
  248.         for (int i = 0; i < all.size(); i++) {
  249.             JSONObject userobj = (JSONObject)all.get(i);
  250.             User user = new User();
  251.             user.username = (String)userobj.get("username");
  252.             user.password = (String)userobj.get("password");
  253.             ans[i] = user;
  254.         }
  255.        
  256.         return ans;
  257.     }
  258.    
  259.     public static void getProxies(String[] proxyIPs, String[] proxyPorts) throws InterruptedException {
  260.        
  261.         WebDriver proxyGetter = new FirefoxDriver();
  262.         int cnt = 0;
  263.        
  264.         proxyGetter.get("https://free-proxy-list.net/");
  265.        
  266.         wait(proxyGetter, "//*[@id=\"proxylisttable\"]", 100);
  267.        
  268.         for (int i = 0; i < 3; i++) {
  269.            
  270.             List <WebElement> page =
  271.                     proxyGetter.findElements(By.xpath("//table[@id=\"proxylisttable\"]/tbody/tr/td[1]"));
  272.            
  273.             List <WebElement> ports =
  274.                     proxyGetter.findElements(By.xpath("//table[@id=\"proxylisttable\"]/tbody/tr/td[2]"));
  275.            
  276.             for (int j = 0; j < page.size(); j++) {
  277.                
  278.                 proxyIPs[cnt] = page.get(j).getText();
  279.                 proxyPorts[cnt++] = page.get(j).getText();
  280.                
  281.             }
  282.            
  283.             WebElement button = proxyGetter.findElement(By.xpath("//a[@data-dt-idx=\"9\"]"));
  284.             button.click();
  285.             Thread.sleep(300);
  286.         }
  287.        
  288.         proxyGetter.quit();
  289.        
  290.     }
  291.    
  292.     public static void main(String[] args) throws InterruptedException, IOException, ParseException {
  293.        
  294.         mt = new Object();
  295.        
  296.         //System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
  297.         //System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");
  298.        
  299.         User[] users = read();
  300.        
  301.         int n = users.length;
  302.        
  303.         WebDriver[] browsers = new WebDriver[n];
  304.         String[] proxyIPs = new String[60];
  305.         String[] proxyPorts = new String[60];
  306.         Thread[] threads = new Thread[n];
  307.        
  308.         //getProxies(proxyIPs, proxyPorts);
  309.        
  310.         for (int i = 0; i < n; i++) {
  311.             CreateBrowser t = new CreateBrowser(browsers, i);
  312.             threads[i] = t;
  313.             t.start();
  314.         }
  315.        
  316.         for (int i = 0; i < n; i++)
  317.             threads[i].join();
  318.        
  319.        
  320.         for (int i = 0; i < n; i++) {
  321.             Authorize t = new Authorize(browsers, users, i);
  322.             threads[i] = t;
  323.             t.start();
  324.         }
  325.        
  326.         for (int i = 0; i < n; i++)
  327.             threads[i].join();
  328.        
  329.         BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
  330.        
  331.         while (true) {
  332.            
  333.             System.out.println("Введи промокод:");
  334.            
  335.             String code = "";
  336.             code = cin.readLine();
  337.                
  338.             if (code.equals("exit"))
  339.                 break;
  340.            
  341.             for (int i = 0; i < n; i++) {
  342.                 InputCode t = new InputCode(browsers, i, code);
  343.                 threads[i] = t;
  344.                 t.start();
  345.             }
  346.            
  347.             for (int i = 0; i < n; i++)
  348.                 threads[i].join();
  349.            
  350.         }
  351.        
  352.         for (int i = 0; i < n; i++)
  353.             browsers[i].quit();
  354.        
  355.     }
  356. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement