Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 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. p:
  59. for (int i = 0; i < linki.size(); i++) {
  60. fb.get(linki.get(i));
  61. String rozmiar = fb.findElement(By.cssSelector(".title>small")).getText().replace(".", ",");
  62. fb.get("https://darkw.pl/new-topic-f7/");
  63.  
  64. Random r = new Random();
  65. int index = r.nextInt(7);
  66. String[] loginHaslo = konta.get(index).split(":");
  67.  
  68. fb.findElement(By.cssSelector("input[name='loginUserLogin']")).sendKeys(loginHaslo[0]);
  69. fb.findElement(By.cssSelector("input[name='loginUserPass']")).sendKeys(loginHaslo[1]);
  70. fb.findElement(By.cssSelector("button[onclick='loader(); document.userLogin.submit();'")).click();
  71.  
  72. fb.findElement(By.cssSelector("input[name='postTitle']")).sendKeys("rapidu " + rozmiar);
  73. fb.findElement(By.cssSelector("textarea[name='postMessage']")).sendKeys("[code]" + linki.get(i) + "[/code]");
  74. fb.findElement(By.cssSelector("div[onclick=\"$('#postOption').val('0'); loader(); document.newTopic.submit();\"")).click();
  75.  
  76. System.out.println("dodaję post: " + (1 + i) + " z " + linki.size());
  77. Thread.sleep(45000);
  78.  
  79. int licznik = 0;
  80. while (true) {
  81.  
  82. fb.get(fb.getCurrentUrl());
  83. List<WebElement> code = fb.findElements(By.cssSelector("code"));
  84. if (code.size() > 1) {
  85. System.out.println("zapis do pliku: " + code.get(1).getText());
  86. zapiszDoPliku(code.get(1).getText(), "wygenerowane");
  87. fb.get("https://darkw.pl/logout/");
  88. break;
  89. } else {
  90. licznik++;
  91. Thread.sleep(10000);
  92. System.out.println("Odświeżam post: " + fb.getCurrentUrl());
  93. System.out.println("licznik: " + licznik);
  94. }
  95. if (licznik == 24) {
  96. i--;
  97. fb.get("https://darkw.pl/logout/");
  98. System.out.println("continue");
  99. continue p;
  100. }
  101. }
  102. }
  103. fb.quit();
  104. } catch (IOException ex) {
  105. Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
  106. } catch (InterruptedException ex) {
  107. Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
  108. }
  109. }).start();
  110.  
  111. }
  112.  
  113. public static void zapiszDoPliku(String text, String nazwa) {
  114.  
  115. try (FileWriter fw = new FileWriter("src/" + nazwa + ".txt", true);
  116. BufferedWriter bw = new BufferedWriter(fw);
  117. PrintWriter out = new PrintWriter(bw)) {
  118. out.println(text);
  119.  
  120. } catch (IOException e) {
  121.  
  122. System.out.println("brak pliku");
  123. }
  124.  
  125. }
  126.  
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement