URL = "https://www.flashscore.com/football/england/premier-league-2018-2019/results/"; // <= WEBSITE YOU WANT TO SCRAPE WEB_BROWSER = "C:\\BIN\\SUPERMIUM\\chrome.exe"; // <= PUT YOUR WEB BROWSER'S FULL NAME AND PATH HERE WEB_BROWSER_NAME = "Supermium"; // <= PUT YOUR WEB BROWSER'S SHORT NAME HERE try { FSO = new ActiveXObject("Scripting.FileSystemObject"); WshShell = WScript.CreateObject("WScript.Shell"); } catch (e) { ABORT("The script cannot access the file system!"); } ContinueOrExit("This script will try to open the web browser " + WEB_BROWSER_NAME + ", load a website and\n" + "copy the contents and save it in a file called Scraper.txt."); ALERT("This program will run for approx. 20 seconds after\nyou press the OK button, and then\nit will terminate and say \"done\"."); RUN(QUOTE(WEB_BROWSER) + " " + QUOTE(URL)); WAIT(5); WINFOCUS( WEB_BROWSER_NAME ); WAIT(10); // WAIT FOR PAGE TO FULLY LOAD. GIVE IT ABOUT 10 SECONDS. PRESS("{ESCAPE}"); // SEND ESC KEYSTROKE TO CLOSE POPUP AD ON THE WEBSITE WAIT(0.2); PRESS("^{a}"); // SEND CTRL+A KEYSTROKE (SELECT ALL) WAIT(0.05); PRESS("^{a}"); // SEND CTRL+A KEYSTROKE AGAIN JUST IN CASE WAIT(0.2); PRESS("^{INSERT}"); // SEND CTRL+INSERT KEYSTROKE (COPY TEXT) WAIT(0.2); TEXT = ReadClipboardText(); CURDIR = GetCurDir(); // GET CURRENT DIRECTORY // Note: When you save using CreateFile(), this will discard ALL // unicode characters from the TEXT. If you want to save Unicode // characters in the output, then use CreateUnicodeFile() // function instead: // Here we remove everything that appears BEFORE the first occurrence of "Premier League" // We only keep the text that appears after this text: TEXT = StrAfter(TEXT, "Premier League"); // And here we remove everything that appears AFTER the last occurrence of "Show more matches" // We only keep whatever we have before this text: TEXT = StrBefore(TEXT, "Show more matches"); // So, we're left with the results, and we save that in a text file: CreateFile(CURDIR + "Scraper.txt", TEXT); SAY("done"); EXIT(); // END OF SCRIPT //////////////////////////////////////////////////////////////////// // // F U N C T I O N S // // This function displays a simple OK popup message box. function ALERT(MSG) { WScript.Echo(MSG); } // Display an error message and terminate the script. function ABORT(MSG) { EXIT("Error: " + MSG); } // Display a message and terminate the script. function EXIT(MSG) { if (typeof(MSG) != "undefined") ALERT(MSG); WScript.Quit(0); } // Show a popup box, display a Yes/No question, and return the user's response. function YES(QUESTION, TITLE) { try { if (WshShell.Popup(QUESTION, 0, (typeof(TITLE) == "string" ? TITLE : "Question"), 36) == 6) return 1; } catch (e) {} return 0; } // Asks whether to continue the script or not. If user selects no, then terminates the script. function ContinueOrExit(QUESTION) { if (!YES(QUESTION + "\n\nContinue?", "Do you want to continue?")) EXIT(); } // This function returns the current directory with a backslash at the end. function GetCurDir() { return WScript.ScriptFullName.replace(/\\[^\\]+$/, "\\"); } // This function will run a separate program which will be independent from this script. function RUN(CMD) { WshShell.Run(CMD, 9); } // This function will transfer focus to the named application. This function does not work in every situation. // If it doesn't work, try to substitute it by sending ALT+TAB keycode, which will bring into focus // the other running app. Make sure there are no other windows open! function WINFOCUS(W) { WshShell.AppActivate(W); } // This script will wait for N seconds and then continue execution of the script. function WAIT(N) { WScript.Sleep(N * 1000); } // This function will use the builtin text-to-speech engine of Windows to say a sentence in English. function SAY(TEXT) { var VOICE = WScript.CreateObject("SAPI.SpVoice"); VOICE.Volume = 100; VOICE.Speak(TEXT); } // This function sends a keypress to the currently running app. function PRESS(KEYCODE) { WAIT(0.1); WshShell.SendKeys(KEYCODE); } // This function inserts double quotes around a string. function QUOTE(S) { return '"' + S + '"'; } // This function returns a section of string S that comes before the LAST occurrence of string M. The match is case sensitive. function StrBefore(S, M) { var E = S.lastIndexOf(M); return (E > 0) ? S.substr(0, E) : ""; } // This function returns a section of string S that comes after the FIRST occurrence of string M. The match is case sensitive. function StrAfter(S, M) { var E = S.indexOf(M); return (E > 0) ? S.slice(E + M.length) : ""; } //////////////////////////////////////////////////////////////////// // // This function creates and overwrites a file in plain text ASCII mode. // Return 1 on success or 0 if an error occurred. // // Usage: INTEGER = CreateFile(FILENAME, STRING) // function CreateFile(FILENAME, S) { S += ""; // Ensure that no errors will occur during write: // Here we convert certain special characters which would cause // a "hiccup" with the Write() function when we have the // file open in plain text ASCII mode. S = S.replace(/[^\x00-\xFF]+/g, ""); S = S.replace(/[\x80-\x9F]{1}/g, function (c, x) { return "\u20AC\x81\u201A\u0192\u201E\u2026\u2020\u2021\u02C6\u2030\u0160\u2039\u0152\x8D\u017D\x8F\x90\u2018\u2019\u201C\u201D\u2022\u2013\u2014\u02DC\u2122\u0161\u203A\u0153\x9D\u017E\u0178".charAt(x - 128); }); try { var FILE = FSO.CreateTextFile(FILENAME, 1, 0); // Create plain ASCII file. FILE.Write(S); FILE.Close(); return 1; } catch (e) {} return 0; } //////////////////////////////////////////////////////////////////// // // This function creates and overwrites a file with a string that // may contain Unicode characters. The file will be saved in // UTF-16BE format! The function returns 1 on success or // zero if an error occurred. // // Usage: INTEGER = CreateUnicodeFile(FILENAME, STRING) // function CreateUnicodeFile(FILENAME, S) { try { var FILE = FSO.CreateTextFile(FILENAME, 1, 1); // Create UTF16 file FILE.Write(S); FILE.Close(); return 1; } catch (e) {} return 0; } //////////////////////////////////////////////////////////////////// // // This function copies all text from the clipboard. We accomplish // this by launching Internet Explorer in the background. We create // a document with a textbox for user input. We paste whatever is // on the clipboard into the textarea, and then we read its content // and return the string. This process takes about 200ms. // // Usage: STRING = ReadClipboardText() // function ReadClipboardText() { var MSIE = WScript.CreateObject("InternetExplorer.Application"); MSIE.Visible = 0; MSIE.Navigate("about:blank"); var HTML = "