forked from nonkit/ArticleList
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WikiArticleList.sb
231 lines (231 loc) · 7.52 KB
/
WikiArticleList.sb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
' TechNet Wiki Article List 0.3
' Copyright © 2015-2017 Nonki Takahashi. The MIT License.
' Last update 2017-09-23
' Program ID WWJ884-4
'
TextWindow.Title = "TechNet Wiki Article List 0.3"
Not = "False=True;True=False;"
qt = Text.GetCharacter(34)
LT = "<"
root = "https://social.technet.microsoft.com"
tags = "1=BASIC;2=VB;3=VB.NET;4=visual basic;5=visual basic.net;6=VB .NET;7=vba;8=excel vba;9=visual basic 10;10=VB.Net 2008;11=VB2008;12=visual basic 2010;13=vb.net 2012;14=VB2013;15=VB2015;"
tags = "1=Small Basic;"
nArticle = 0
stdout = Program.Directory + "/list.html"
File.WriteContents(stdout, LT + "!DOCTYPE html>")
File.AppendContents(stdout, LT + "html lang=" + qt + "en" + qt + ">")
File.AppendContents(stdout, LT + "head>")
File.AppendContents(stdout, LT + "meta charset=" + qt + "UTF-8" + qt + ">")
File.AppendContents(stdout, LT + "title>TechNet Wiki Article List" + LT + "/title>")
File.AppendContents(stdout, LT + "/head>")
File.AppendContents(stdout, LT + "body>")
File.AppendContents(stdout, LT + "p>TechNet Wiki Article List - " + Clock.Date + LT + "/p>")
File.AppendContents(stdout, LT + "table>")
File.AppendContents(stdout, LT + "tr>")
File.AppendContents(stdout, LT + "td>TITLE</td>")
File.AppendContents(stdout, LT + "td>LAST REVISION BY" + LT + "/td>")
File.AppendContents(stdout, LT + "td>CREATION DATE" + LT + "/td>")
File.AppendContents(stdout, LT + "td>TAGS" + LT + "/td>")
File.AppendContents(stdout, LT + "/tr>")
nTag = Array.GetItemCount(tags)
For iTag = 1 To nTag
eob = "False" ' end of blog
EncodeTag()
url = root + "/wiki/contents/articles/tags/" + encoded + "/default.aspx"
site = url
pageIndex = 1
pageLast = ""
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
File.AppendContents(stdout, LT + "tr>")
bufSave = buf
pH4 = p
p = 1
buf = tag
param = "tag=a;"
FindTag()
GetAttrAndText()
File.AppendContents(stdout, LT + "td>" + LT + "a href=" + qt + attr["href"] + qt + ">" + txt + LT + "/a>" + LT + "/td>")
nArticle = nArticle + 1
buf = bufSave
p = pH4
param = "tag=a;class=internal-link view-user-profile;"
FindTag()
If tag = "" Then
File.AppendContents(stdout, LT + "td> " + LT + "/td>")
File.AppendContents(stdout, LT + "td> " + LT + "/td>")
File.AppendContents(stdout, LT + "td> " + LT + "/td>")
File.AppendContents(stdout, LT + "/tr>")
eod = "True"
Else
GetAttrAndText()
File.AppendContents(stdout, LT + "td>" + LT + "a href="+ qt + root + attr["href"] + qt + ">" + txt + "" + LT + "/a>" + LT + "/td>")
param = "tag=div;class=post-date;"
FindTag()
If tag = "" Then
File.AppendContents(stdout, LT + "td> " + LT + "/td>")
File.AppendContents(stdout, LT + "td> " + LT + "/td>")
File.AppendContents(stdout, LT + "/tr>")
eod = "True"
Else
pDiv = p
bufSave = buf
p = 1
buf = tag
param = "tag=span;class=value;"
FindTag()
GetAttrAndText()
File.AppendContents(stdout, LT + "td>" + txt + LT + "/td>")
File.AppendContents(stdout, LT + "td>" + tags[iTag] + LT + "/td>")
File.AppendContents(stdout, LT + "/tr>")
buf = bufSave
p = pDiv
EndIf
EndIf
EndIf
EndWhile
pageIndex = pageIndex + 1
If pageLast = "" Then
param = "tag=span;class=summary;"
FindTag()
If tag = "" Then
eob = "True"
Else
GetAttrAndText()
lenPage = Text.GetIndexOf(Text.GetSubTextToEnd(txt, 11), " ") - 1
pageLast = Text.GetSubText(txt, 11, lenPage)
EndIf
EndIf
site = url + "?PageIndex=" + pageIndex
If pageLast < pageIndex Then
eob = "True"
EndIf
EndWhile
EndFor
File.AppendContents(stdout, LT + "/table>")
File.AppendContents(stdout, LT + "p>Total " + nArticle + " articles." + LT + "/p>")
File.AppendContents(stdout, LT + "/body>")
File.AppendContents(stdout, LT + "/html>")
TextWindow.WriteLine("Total " + nArticle + " articles.")
Sub EncodeTag
' param tags - array for tags
' param iTag - index of the array for tags
' return encoded - encoded tag
encoded = ""
len = Text.GetLength(tags[iTag])
For i = 1 To len
c = Text.GetSubText(tags[iTag], i, 1)
If c = " " Then
c = "+"
ElseIf c = "." Then
c = "-"
ElseIf c = "#" Then
c = "_2300_"
ElseIf c = "+" Then
c = "_2B00_"
ElseIf c = "-" Then
c = "_2D00_"
EndIf
If Text.EndsWith(encoded, "_") And Text.StartsWith(c, "_") Then
l1 = Text.GetLength(encoded) - 1
encoded = Text.Append(Text.GetSubText(encoded, 1, l1), Text.GetSubTextToEnd(c, 2))
Else
encoded = Text.Append(encoded, c)
EndIF
EndFor
EndSub
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), LT + 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), LT)
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