Microsoft Small Basic

Program Listing: WWJ884-0
' TechNet Wiki Article List 0.11
' Copyright © 2015 Nonki Takahashi. The MIT License.
' Last update 2015-02-10
' Program ID WWJ884-0
'
TextWindow.Title = "TechNet Wiki Article List 0.11"
Not = "False=True;True=False;"
root = "http://social.technet.microsoft.com"
tags = "Small+Basic"
url = root + "/wiki/contents/articles/tags/" + tags + "/default.aspx"
site = url
qt = Text.GetCharacter(34)
eob = "False" ' end of blog
first = "True"
nArticle = 0
stdout = Program.Directory + "/list.html"
' The following line could be harmful and has been automatically commented.
' File.WriteContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "TechNet Wiki - " + tags + " - Table of Contents")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "

TechNet Wiki Articles tagged as " + tags + "

")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
pageIndex = 1
While Not[eob]
TextWindow.WriteLine(site)
buf = Network.GetWebPageContents(site)
pNotFound = Text.GetLength(buf) + 1
p = 1
eod = "False"
While Not[eod]
param = "tag=h4;class=post-name;"
FindTag()
If tag = "" Then
eod = "True"
Else
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout,"")
bufSave = buf
pH4 = p
p = 1
buf = tag
param = "tag=a;"
FindTag()
GetAttrAndText()
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
nArticle = nArticle + 1
buf = bufSave
p = pH4
param = "tag=a;class=internal-link view-user-profile;"
FindTag()
If tag = "" Then
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
eod = "True"
Else
GetAttrAndText()
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
param = "tag=div;class=post-date;"
FindTag()
If tag = "" Then
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
eod = "True"
Else
pDiv = p
bufSave = buf
p = 1
buf = tag
param = "tag=span;class=value;"
FindTag()
GetAttrAndText()
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
buf = bufSave
p = pDiv
EndIf
EndIf
EndIf
EndWhile
pageIndex = pageIndex + 1
If pageLast = "" Then
param = "tag=a;class=last;"
FindTag()
If tag = "" Then
eob = "True"
Else
GetAttrAndText()
pEq = Text.GetIndexOf(attr["href"], "=")
pageLast = Text.GetSubTextToEnd(attr["href"], pEq + 1)
EndIf
EndIf
site = url + "?PageIndex=" + pageIndex
If pageLast < pageIndex Then
eob = "True"
EndIf
EndWhile
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "
TITLELAST REVISION BYCREATION DATE
" + txt + "
" + txt + "
" + txt + "
")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "

Total " + nArticle + " articles.

")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
TextWindow.WriteLine("Total " + nArticle + " articles.")
Sub FindTag
' find tag from html buffer
' param["tag"] - tag name
' param["class"] - class name
' param p - pointer for buffer
' param buf - html buffer
' return tag - found tag
pSave = p
tag = ""
findNext = "True"
While findNext
findNext = "False" ' tag may be not found
pTag = Text.GetIndexOf(Text.GetSubTextToEnd(buf, p), "<" + param["tag"])
If 0 < pTag Then
lTag = Text.GetLength(param["tag"]) + 1
pTag = p + pTag - 1
len = Text.GetIndexOf(Text.GetSubTextToEnd(buf, pTag), "/" + param["tag"] + ">")
If param["class"] = "" Then
len = len + lTag
tag = Text.GetSubText(buf, pTag, len)
findNext = "False" ' found the tag
ElseIf 0 < len Then
findNext = "True" ' tag may have different class
len = len + lTag
attr = "class=" + qt + param["class"] + qt
pAttr = pTag + lTag + 1
lAttr = Text.GetLength(attr)
If Text.GetSubText(buf, pAttr, lAttr) = attr Then
tag = Text.GetSubText(buf, pTag, len)
findNext = "False" ' found the tag
EndIf
p = pTag + len
EndIf
EndIf
EndWhile
If tag = "" Then
p = pSave
EndIf
EndSub
Sub GetAttrAndText
' get attributes and text from given tag
' param tag - given tag
' return attr[] - array of attributes in the tag
' return txt - text in the tag
pTag = Text.GetIndexOf(tag, " ") + 1
pEnd = Text.GetIndexOf(tag, ">")
attr = ""
While pTag <= pEnd
pEq = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), "=")
If 0 < pEq Then
pEq = pTag + pEq - 1
If Text.GetSubText(tag, pEq + 1, 1) = qt Then
pQ = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pEq + 2), qt)
If 0 < pQ Then
pQ = pEq + 2 + pQ - 1
attr[Text.GetSubText(tag, pTag, pEq - pTag)] = Text.GetSubText(tag, pEq + 2, pQ - pEq - 2)
pTag = pQ + 2
EndIf
EndIf
Else
pTag = pEnd + 1
EndIf
EndWhile
If pEnd + 1 < pTag Then
pTag = pEnd + 1
EndIf
len = Text.GetLength(tag)
txt = ""
While pTag <= len
pL = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), "<")
If pL = 0 Then
txt = Text.Append(txt, Text.GetSubTextToEnd(tag, pTag))
pTag = len + 1
Else
pL = pTag + pL - 1
txt = Text.Append(txt, Text.GetSubText(tag, pTag, pL - pTag))
pR = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), ">")
If 0 < pR Then
pTag = pTag + pR
Else
pTag = len + 1
EndIf
EndIf
EndWhile
EndSub