Advertisement
TheDemystifier

CBT Nuggets Transcript

Jun 7th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileWriter;
  3. import java.io.IOException;
  4.  
  5. public class Testing {
  6.     public static void main(String[] args) {
  7.         String filePath = "H:/result.txt"; // This is the file which will have the end-result
  8.         new File(filePath).delete(); // Delete it so we start a new fresh operation
  9.         String allLines = "";
  10.         for (int video = 1; video <= 200; video++) {
  11.             System.out.println(video); // Just to keep an eye on the progress
  12.             allLines += "\n" + "SET !TIMEOUT_STEP 6";    // Keep waiting for 6 seconds for the element before returning an error in case there are no elements left
  13.             allLines += "\n" + "TAG SELECTOR=\"#tabstranscript > div > div > div:nth-child(" + video + ") > p\"";
  14.             allLines += "\n" + "WAIT SECONDS=5";
  15.             allLines += "\n" + "SET !TIMEOUT_STEP 0";   // When you don't find the element, move on, don't keep waiting for it, this is so that we can keep the number of lines dynamic, I have accounted for the max possible
  16.             for (int line = 1; line <= 200; line++) {
  17.                 allLines += "\n" + "TAG SELECTOR=\"#tabstranscript > div > div > div:nth-child(" + video + ") > div > div > div > div:nth-child(" + line + ") > p\" EXTRACT=TXT";
  18.             }
  19.             allLines += "\n" + "SAVEAS TYPE=EXTRACT FOLDER=* FILE=H:\\CBT<SP>Nugget<SP>Transcript.csv";
  20.             allLines += "\n";
  21.             allLines += "\n";
  22.             saveToFile(filePath, true, allLines); // Save the buffer in the file
  23.             allLines = ""; // Free the buffer to speed things up
  24.         }
  25.     }
  26.  
  27.     static void saveToFile(String filePath, boolean append, String linesToWrite) {
  28.         try {
  29.             FileWriter fw = new FileWriter(new File(filePath), append);
  30.             fw.write(linesToWrite);
  31.             fw.close();
  32.         } catch (IOException e) {
  33.             e.printStackTrace();
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement