Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package darkww;
  7.  
  8. import java.io.BufferedWriter;
  9. import java.io.FileOutputStream;
  10. import java.io.FileWriter;
  11. import java.io.IOException;
  12. import java.io.PrintWriter;
  13. import java.net.URL;
  14. import java.nio.charset.StandardCharsets;
  15. import java.nio.file.Files;
  16. import java.nio.file.Paths;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import java.util.Random;
  20. import java.util.ResourceBundle;
  21. import java.util.logging.Level;
  22. import java.util.logging.Logger;
  23. import javafx.event.ActionEvent;
  24. import javafx.fxml.FXML;
  25. import javafx.fxml.Initializable;
  26. import javafx.scene.control.Label;
  27. import org.openqa.selenium.By;
  28. import org.openqa.selenium.WebDriver;
  29. import org.openqa.selenium.WebElement;
  30. import org.openqa.selenium.firefox.FirefoxDriver;
  31.  
  32. /**
  33. *
  34. * @author Piotr
  35. */
  36. public class FXMLDocumentController implements Initializable {
  37.  
  38. @FXML
  39. private Label label;
  40.  
  41. @FXML
  42. private void handleButtonAction(ActionEvent event) {
  43. }
  44.  
  45. @Override
  46. public void initialize(URL url, ResourceBundle rb) {
  47.  
  48. new Thread(() -> {
  49.  
  50. try {
  51. FileOutputStream writer = new FileOutputStream("src/wygenerowane.txt");
  52. List<String> linki = Files.readAllLines(Paths.get("src/linki.txt"), StandardCharsets.UTF_8);
  53. List<String> konta = Files.readAllLines(Paths.get("src/konta.txt"), StandardCharsets.UTF_8);
  54. System.setProperty("webdriver.gecko.driver", "C://gecodriver/geckodriver.exe");
  55. System.setProperty("webdriver.firefox.bin", "C:\\Users\\Piotr\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
  56. WebDriver fb = new FirefoxDriver();
  57.  
  58. int index = 0;
  59.  
  60. p:
  61. for (int i = 0; i < linki.size(); i++) {
  62. fb.get(linki.get(i));
  63. String rozmiar = fb.findElement(By.cssSelector(".title>small")).getText().replace(".", ",");
  64. fb.get("https://darkw.pl/new-topic-f7/");
  65.  
  66. // Random r = new Random();
  67. // int index = r.nextInt(7);
  68. if (index == linki.size()) {
  69. index = 0;
  70. }
  71. String[] loginHaslo = konta.get(index).split(":");
  72.  
  73. fb.findElement(By.cssSelector("input[name='loginUserLogin']")).sendKeys(loginHaslo[0]);
  74. fb.findElement(By.cssSelector("input[name='loginUserPass']")).sendKeys(loginHaslo[1]);
  75.  
  76. index++;
  77. fb.findElement(By.cssSelector("button[onclick='loader(); document.userLogin.submit();'")).click();
  78.  
  79. fb.findElement(By.cssSelector("input[name='postTitle']")).sendKeys("rapidu " + rozmiar);
  80. fb.findElement(By.cssSelector("textarea[name='postMessage']")).sendKeys("[code]" + linki.get(i) + "[/code]");
  81. fb.findElement(By.cssSelector("div[onclick=\"$('#postOption').val('0'); loader(); document.newTopic.submit();\"")).click();
  82.  
  83. System.out.println("dodaję post: " + (1 + i) + " z " + linki.size());
  84. //Thread.sleep(45000);
  85.  
  86. int licznik = 0;
  87. while (true) {
  88. Thread.sleep(10000);
  89. fb.get(fb.getCurrentUrl());
  90. List<WebElement> code = fb.findElements(By.cssSelector("code"));
  91. if (code.size() > 1) {
  92. System.out.println("zapis do pliku: " + code.get(1).getText());
  93. zapiszDoPliku(code.get(1).getText(), "wygenerowane");
  94. fb.get("https://darkw.pl/logout/");
  95. break;
  96. } else {
  97. licznik++;
  98. //Thread.sleep(10000);
  99. System.out.println("Odświeżam post: " + fb.getCurrentUrl());
  100. System.out.println("licznik: " + licznik);
  101. }
  102. if (licznik == 24) {
  103. i--;
  104. fb.get("https://darkw.pl/logout/");
  105. System.out.println("continue");
  106. continue p;
  107. }
  108. }
  109. }
  110. fb.quit();
  111. } catch (IOException ex) {
  112. Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
  113. } catch (InterruptedException ex) {
  114. Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
  115. }
  116. }).start();
  117.  
  118. }
  119.  
  120. public static void zapiszDoPliku(String text, String nazwa) {
  121.  
  122. try (FileWriter fw = new FileWriter("src/" + nazwa + ".txt", true);
  123. BufferedWriter bw = new BufferedWriter(fw);
  124. PrintWriter out = new PrintWriter(bw)) {
  125. out.println(text);
  126.  
  127. } catch (IOException e) {
  128.  
  129. System.out.println("brak pliku");
  130. }
  131.  
  132. }
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement