Advertisement
TheDemystifier

Memrise Course

Jun 12th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 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 level = 1; level <= 200; level++) {
  11.             System.out.println(level); // Just to keep an eye on the progress
  12.             allLines += "\n" + "TAG SELECTOR=\"div.levels.clearfix > a:nth-of-type(" + level + ")\" EXTRACT=HREF"; // Get the level href
  13.             allLines += "\n" + "TAB OPEN";
  14.             allLines += "\n" + "TAB T=2";
  15.             allLines += "\n" + "URL GOTO={{!EXTRACT}}"; // Go the level
  16.             allLines += "\n" + "SET !EXTRACT NULL";
  17.             allLines += "\n" + "WAIT SECONDS=2";
  18.             allLines += "\n" + "TAG SELECTOR=\"div.infos > h3\" EXTRACT=TXT"; // Extract level title
  19.             allLines += "\n" + "SET levelTitle {{!EXTRACT}}";
  20.             allLines += "\n" + "SET !EXTRACT NULL";
  21.             for (int entry = 4; entry <= 70; entry++) { // we start from 4 because the site has 3 divs above that we're not concerned with
  22.                 allLines += "\n" + "ADD !EXTRACT {{levelTitle}}";
  23.                 allLines += "\n" + "TAG SELECTOR=\"div.things.clearfix > div.thing.text-text:nth-of-type(" + entry + ") > div.col_a.col.text > div\" EXTRACT=TXT";
  24.                 allLines += "\n" + "TAG SELECTOR=\"div.things.clearfix > div.thing.text-text:nth-of-type(" + entry + ") > div.col_b.col.text > div\" EXTRACT=TXT";
  25.                 allLines += "\n" + "SAVEAS TYPE=EXTRACT FOLDER=* FILE=H:\\Memrise<SP>Course.csv";
  26.             }
  27.             allLines += "\n" + "TAB T=1";
  28.             allLines += "\n" + "TAB CLOSEALLOTHERS";
  29.             allLines += "\n";
  30.             allLines += "\n";
  31.             saveToFile(filePath, true, allLines); // Save the buffer in the file
  32.             allLines = ""; // Free the buffer to speed things up
  33.         }
  34.     }
  35.  
  36.     static void saveToFile(String filePath, boolean append, String linesToWrite) {
  37.         try {
  38.             FileWriter fw = new FileWriter(new File(filePath), append);
  39.             fw.write(linesToWrite);
  40.             fw.close();
  41.         } catch (IOException e) {
  42.             e.printStackTrace();
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement