Advertisement
TheDemystifier

CBT Nuggets Descriptions

Jul 7th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 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" + "TAG SELECTOR=\"#videoApp tbody:nth-child(" + video + ") .video_title \" EXTRACT=TXT";   // Extract the title
  13.             allLines += "\n" + "TAG SELECTOR=\"#videoApp tbody:nth-child(" + video + ") .video-description \" EXTRACT=TXT";   // Extract the Description
  14.             allLines += "\n" + "SAVEAS TYPE=EXTRACT FOLDER=* FILE=H:\\CBT<SP>Nugget<SP>Descriptions.csv";
  15.             allLines += "\n";
  16.             allLines += "\n";
  17.             saveToFile(filePath, true, allLines); // Save the buffer in the file
  18.             allLines = ""; // Free the buffer to speed things up
  19.         }
  20.     }
  21.  
  22.     static void saveToFile(String filePath, boolean append, String linesToWrite) {
  23.         try {
  24.             FileWriter fw = new FileWriter(new File(filePath), append);
  25.             fw.write(linesToWrite);
  26.             fw.close();
  27.         } catch (IOException e) {
  28.             e.printStackTrace();
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement