Microsoft Small Basic

Program Listing:
Embed this in your website
' Google Blog Article List 0.3
' Copyright © 2014 Nonki Takahashi. The MIT License.
' Last update 2014-12-30
'
TextWindow.Title = "Google Blog Article List 0.3"
Not = "False=True;True=False;"
site = "http://nonkit.blogspot.jp/"
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,"Nonkit Blog - 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,"")
While Not[eob]
  TextWindow.WriteLine(site)
  buf = Network.GetWebPageContents(site)
  pNotFound = Text.GetLength(buf) + 1
  p = 1
  eod = "False"
  While Not[eod]
    param = "tag=h2;class=date-header;"
    FindTag()
    pH2 = pNotFound
    If tag <> "" Then
      pH2 = p
      tagH2 = tag
    EndIf
    p = pSave
    param = "tag=h3;class=post-title entry-title;"
    FindTag()
    pH3 = pNotFound
    If tag <> "" Then
      pH3 = p
      tagH3 = tag
    EndIf
    p = pSave
    If pH2 < pNotFound And pH3 < pNotFound Then
      If pH2 < pH3 Then
        pH3 = pNotFound
      ElseIf pH3 < pH2 Then
        pH2 = pNotFound
      EndIf
    EndIf
    If pH2 < pNotFound Then
      tag = tagH2
      bufSave = buf
      p = 1
      buf = tag
      param = "tag=span;"
      FindTag()
      GetAttrAndText()
      If first Then
        first = "False"
      Else
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "")
      EndIf
' The following line could be harmful and has been automatically commented.
' File.AppendContents(stdout, "

" + txt + "

    ")
          buf = bufSave
          p = pH2
        ElseIf pH3 < pNotFound Then
          tag = tagH3
          bufSave = buf
          p = 1
          buf = tag
          param = "tag=a;"
          FindTag()
          GetAttrAndText()
    ' The following line could be harmful and has been automatically commented.
    ' File.AppendContents(stdout, "
  • " + txt + "
  • ")

          nArticle = nArticle + 1
          buf = bufSave
          p = pH3
        EndIf
        If pH2 = pNotFound And pH3 = pNotFound Then
          eod = "True"
        EndIf
      EndWhile
      param = "tag=a;class=blog-pager-older-link;"
      FindTag()
      If tag = "" Then
        eob = "True"
      Else
        GetAttrAndText()
        site = attr["href"]
      EndIf
    EndWhile
    ' 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, "

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, "")
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=" + "'" + param["class"] + "'"
        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) = "'" Then
        pQ = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pEq + 2), "'")
        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
Copyright (c) Microsoft Corporation. All rights reserved.