Jump to content

Wikipedia:WikiProject User scripts/Scripts/VBS/Savewatchlisttofile

From Wikipedia, the free encyclopedia
'Author: Smallman12q (http://en.wikipedia.org/wiki/User:Smallman12q)'Date: Feb 21, 2012'Desc: Sample VBscript for logging into English wiki, saving watchlist to file, logging out, and closing IE'Usability: This is a sample, tutorial script. It does not include error handling.'URL: http://en.wikipedia.org/wiki/User:Smallman12q/VBS/SavewatchlistOptionExplicit''''''''''''''''''''''''''User Set Variables'''''These can be changedDimuser,userpass,watchlistfilenameuser="user"userpass="userpass"watchlistfilename="Watchlist.txt"'Will save to Desktop, Will overwrite file if it exists'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''LoginDimoIESetoIE=CreateObject("InternetExplorer.application")WithoIE.Visible=True.Navigate("https://en.wikipedia.org/w/index.php?title=Special:UserLogin")EndWithDoUntiloIE.ReadyState=4'readystate 4 = done loadingwscript.sleep200LoopWithoIE.Document.forms("userlogin").wpName.Value=user.wpPassword.Value=userpass.submitEndWith'Wait 2 seconds to show user we've logged inWScript.Sleep1000'Go to raw watchlistoIE.Navigate("https://en.wikipedia.org/wiki/Special:EditWatchlist/raw")DoUntiloIE.ReadyState=4'readystate 4 = done loadingwscript.sleep200Loop'Get Watchlist dataDimitmSetitm=oIE.document.getElementById("mw-input-wpTitles")'Write data to file on desktopifNOT(itmisnothing)ThenDimoFSO,WriteData,desktopDimWSHShellSetWSHShell=WScript.CreateObject("WScript.Shell")Desktop=WSHShell.SpecialFolders("Desktop")SetoFSO=CreateObject("Scripting.FileSystemObject")SetWriteData=oFSO.CreateTextFile(desktop&"\"&watchlistfilename,true,true)'Overwrite in UnicodeWriteData.WriteLine(itm.Value)WriteData.Close'To do: Clear out variablesEndIf'Ask if to logoutIfmsgbox("The Watchlist has been saved. Do you want to log out?",vbYesNo,"Logout Prompt")Then'LogoutoIE.Navigate("https://en.wikipedia.org/w/index.php?title=Special:UserLogout")DoUntiloIE.ReadyState=4'readystate 4 = done loadingwscript.sleep200Loop'Ask if to close windowIfmsgbox("You have been logged out. Would you like to close IE?",vbYesNo,"Close IE Prompt")ThenoIE.QuitEndifEndif
close