Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- public class Testing {
- public static void main(String[] args) {
- String filePath = "H:/result.txt"; // This is the file which will have the end-result
- new File(filePath).delete(); // Delete it so we start a new fresh operation
- String allLines = "";
- for (int video = 1; video <= 200; video++) {
- System.out.println(video); // Just to keep an eye on the progress
- 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
- allLines += "\n" + "TAG SELECTOR=\"#tabstranscript > div > div > div:nth-child(" + video + ") > p\"";
- allLines += "\n" + "WAIT SECONDS=5";
- 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
- for (int line = 1; line <= 200; line++) {
- allLines += "\n" + "TAG SELECTOR=\"#tabstranscript > div > div > div:nth-child(" + video + ") > div > div > div > div:nth-child(" + line + ") > p\" EXTRACT=TXT";
- }
- allLines += "\n" + "SAVEAS TYPE=EXTRACT FOLDER=* FILE=H:\\CBT<SP>Nugget<SP>Transcript.csv";
- allLines += "\n";
- allLines += "\n";
- saveToFile(filePath, true, allLines); // Save the buffer in the file
- allLines = ""; // Free the buffer to speed things up
- }
- }
- static void saveToFile(String filePath, boolean append, String linesToWrite) {
- try {
- FileWriter fw = new FileWriter(new File(filePath), append);
- fw.write(linesToWrite);
- fw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement