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 level = 1; level <= 200; level++) {
- System.out.println(level); // Just to keep an eye on the progress
- allLines += "\n" + "TAG SELECTOR=\"div.levels.clearfix > a:nth-of-type(" + level + ")\" EXTRACT=HREF"; // Get the level href
- allLines += "\n" + "TAB OPEN";
- allLines += "\n" + "TAB T=2";
- allLines += "\n" + "URL GOTO={{!EXTRACT}}"; // Go the level
- allLines += "\n" + "SET !EXTRACT NULL";
- allLines += "\n" + "WAIT SECONDS=2";
- allLines += "\n" + "TAG SELECTOR=\"div.infos > h3\" EXTRACT=TXT"; // Extract level title
- allLines += "\n" + "SET levelTitle {{!EXTRACT}}";
- allLines += "\n" + "SET !EXTRACT NULL";
- for (int entry = 4; entry <= 70; entry++) { // we start from 4 because the site has 3 divs above that we're not concerned with
- allLines += "\n" + "ADD !EXTRACT {{levelTitle}}";
- allLines += "\n" + "TAG SELECTOR=\"div.things.clearfix > div.thing.text-text:nth-of-type(" + entry + ") > div.col_a.col.text > div\" EXTRACT=TXT";
- allLines += "\n" + "TAG SELECTOR=\"div.things.clearfix > div.thing.text-text:nth-of-type(" + entry + ") > div.col_b.col.text > div\" EXTRACT=TXT";
- allLines += "\n" + "SAVEAS TYPE=EXTRACT FOLDER=* FILE=H:\\Memrise<SP>Course.csv";
- }
- allLines += "\n" + "TAB T=1";
- allLines += "\n" + "TAB CLOSEALLOTHERS";
- 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