'Author: Smallman12q (http://en.wikipedia.orgview_html.php?sq=Google&lang=en&q=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.orgview_html.php?sq=Google&lang=en&q=User:Smallman12q/VBS/Savewatchlist
Option Explicit
''''''''''''''''''''''''''User Set Variables'''''These can be changed
Dim user,userpass,watchlistfilename
user = "user"
userpass = "userpass"
watchlistfilename = "Watchlist.txt" 'Will save to Desktop, Will overwrite file if it exists
''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''
'Login
Dim oIE
Set oIE = CreateObject("InternetExplorer.application")
With oIE
.Visible = True
.Navigate ("https://en.wikipedia.org/w/index.php?title=Special:UserLogin")
End With
Do Until oIE.ReadyState = 4 'readystate 4 = done loading
wscript.sleep 200
Loop
With oIE.Document.forms("userlogin")
.wpName.Value = user
.wpPassword.Value = userpass
.submit
End With
'Wait 2 seconds to show user we've logged in
WScript.Sleep 1000
'Go to raw watchlist
oIE.Navigate ("https://en.wikipedia.orgview_html.php?sq=Google&lang=en&q=Special:EditWatchlist/raw")
Do Until oIE.ReadyState = 4 'readystate 4 = done loading
wscript.sleep 200
Loop
'Get Watchlist data
Dim itm
Set itm = oIE.document.getElementById("mw-input-wpTitles")
'Write data to file on desktop
if NOT (itm is nothing) Then
Dim oFSO, WriteData, desktop
Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")
Desktop= WSHShell.SpecialFolders("Desktop")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set WriteData = oFSO.CreateTextFile(desktop & "\" & watchlistfilename, true, true) 'Overwrite in Unicode
WriteData.WriteLine(itm.Value)
WriteData.Close
'To do: Clear out variables
End If
'Ask if to logout
If msgbox ("The Watchlist has been saved. Do you want to log out?", vbYesNo, "Logout Prompt") Then
'Logout
oIE.Navigate ("https://en.wikipedia.org/w/index.php?title=Special:UserLogout")
Do Until oIE.ReadyState = 4 'readystate 4 = done loading
wscript.sleep 200
Loop
'Ask if to close window
If msgbox ("You have been logged out. Would you like to close IE?", vbYesNo, "Close IE Prompt") Then
oIE.Quit
End if
End if