Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package darkww;
- import java.io.BufferedWriter;
- import java.io.FileOutputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.net.URL;
- import java.nio.charset.StandardCharsets;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import java.util.ResourceBundle;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.Label;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.firefox.FirefoxDriver;
- /**
- *
- * @author Piotr
- */
- public class FXMLDocumentController implements Initializable {
- @FXML
- private Label label;
- @FXML
- private void handleButtonAction(ActionEvent event) {
- }
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- new Thread(() -> {
- try {
- FileOutputStream writer = new FileOutputStream("src/wygenerowane.txt");
- List<String> linki = Files.readAllLines(Paths.get("src/linki.txt"), StandardCharsets.UTF_8);
- List<String> konta = Files.readAllLines(Paths.get("src/konta.txt"), StandardCharsets.UTF_8);
- System.setProperty("webdriver.gecko.driver", "C://gecodriver/geckodriver.exe");
- System.setProperty("webdriver.firefox.bin", "C:\\Users\\Piotr\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
- WebDriver fb = new FirefoxDriver();
- int index = 0;
- p:
- for (int i = 0; i < linki.size(); i++) {
- fb.get(linki.get(i));
- String rozmiar = fb.findElement(By.cssSelector(".title>small")).getText().replace(".", ",");
- fb.get("https://darkw.pl/new-topic-f7/");
- // Random r = new Random();
- // int index = r.nextInt(7);
- if (index == linki.size()) {
- index = 0;
- }
- String[] loginHaslo = konta.get(index).split(":");
- fb.findElement(By.cssSelector("input[name='loginUserLogin']")).sendKeys(loginHaslo[0]);
- fb.findElement(By.cssSelector("input[name='loginUserPass']")).sendKeys(loginHaslo[1]);
- index++;
- fb.findElement(By.cssSelector("button[onclick='loader(); document.userLogin.submit();'")).click();
- fb.findElement(By.cssSelector("input[name='postTitle']")).sendKeys("rapidu " + rozmiar);
- fb.findElement(By.cssSelector("textarea[name='postMessage']")).sendKeys("[code]" + linki.get(i) + "[/code]");
- fb.findElement(By.cssSelector("div[onclick=\"$('#postOption').val('0'); loader(); document.newTopic.submit();\"")).click();
- System.out.println("dodaję post: " + (1 + i) + " z " + linki.size());
- //Thread.sleep(45000);
- int licznik = 0;
- while (true) {
- Thread.sleep(10000);
- fb.get(fb.getCurrentUrl());
- List<WebElement> code = fb.findElements(By.cssSelector("code"));
- if (code.size() > 1) {
- System.out.println("zapis do pliku: " + code.get(1).getText());
- zapiszDoPliku(code.get(1).getText(), "wygenerowane");
- fb.get("https://darkw.pl/logout/");
- break;
- } else {
- licznik++;
- //Thread.sleep(10000);
- System.out.println("Odświeżam post: " + fb.getCurrentUrl());
- System.out.println("licznik: " + licznik);
- }
- if (licznik == 24) {
- i--;
- fb.get("https://darkw.pl/logout/");
- System.out.println("continue");
- continue p;
- }
- }
- }
- fb.quit();
- } catch (IOException ex) {
- Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
- } catch (InterruptedException ex) {
- Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
- }
- }).start();
- }
- public static void zapiszDoPliku(String text, String nazwa) {
- try (FileWriter fw = new FileWriter("src/" + nazwa + ".txt", true);
- BufferedWriter bw = new BufferedWriter(fw);
- PrintWriter out = new PrintWriter(bw)) {
- out.println(text);
- } catch (IOException e) {
- System.out.println("brak pliku");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement