home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 3_2004-2005.ISO / Data / Zips / Using_MSHT1726533302004.psc / HTML_Element_Parse / frmMain.frm (.txt) next >
Encoding:
Visual Basic Form  |  2004-03-30  |  5.8 KB  |  171 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form frmMain 
  4.    BackColor       =   &H00E0E0E0&
  5.    Caption         =   "HTML Element Parser"
  6.    ClientHeight    =   3510
  7.    ClientLeft      =   60
  8.    ClientTop       =   345
  9.    ClientWidth     =   4335
  10.    Icon            =   "frmMain.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   3510
  13.    ScaleWidth      =   4335
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin MSComctlLib.ImageList ImageList1 
  16.       Left            =   1890
  17.       Top             =   1470
  18.       _ExtentX        =   1005
  19.       _ExtentY        =   1005
  20.       BackColor       =   -2147483643
  21.       ImageWidth      =   16
  22.       ImageHeight     =   16
  23.       MaskColor       =   12632256
  24.       _Version        =   393216
  25.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  26.          NumListImages   =   5
  27.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  28.             Picture         =   "frmMain.frx":058A
  29.             Key             =   ""
  30.          EndProperty
  31.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  32.             Picture         =   "frmMain.frx":0B24
  33.             Key             =   ""
  34.          EndProperty
  35.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  36.             Picture         =   "frmMain.frx":10BE
  37.             Key             =   ""
  38.          EndProperty
  39.          BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  40.             Picture         =   "frmMain.frx":1658
  41.             Key             =   ""
  42.          EndProperty
  43.          BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  44.             Picture         =   "frmMain.frx":1BF2
  45.             Key             =   ""
  46.          EndProperty
  47.       EndProperty
  48.    End
  49.    Begin MSComctlLib.TreeView tv 
  50.       Height          =   3225
  51.       Left            =   60
  52.       TabIndex        =   2
  53.       Top             =   30
  54.       Width           =   3195
  55.       _ExtentX        =   5636
  56.       _ExtentY        =   5689
  57.       _Version        =   393217
  58.       Indentation     =   471
  59.       LabelEdit       =   1
  60.       LineStyle       =   1
  61.       Style           =   7
  62.       ImageList       =   "ImageList1"
  63.       Appearance      =   1
  64.    End
  65.    Begin VB.ListBox List1 
  66.       Height          =   450
  67.       Left            =   60
  68.       Sorted          =   -1  'True
  69.       TabIndex        =   1
  70.       Top             =   30
  71.       Visible         =   0   'False
  72.       Width           =   495
  73.    End
  74.    Begin VB.CommandButton Command1 
  75.       Caption         =   "Parse HTML Elements"
  76.       Height          =   450
  77.       Left            =   600
  78.       TabIndex        =   0
  79.       Top             =   30
  80.       Width           =   2475
  81.    End
  82. Attribute VB_Name = "frmMain"
  83. Attribute VB_GlobalNameSpace = False
  84. Attribute VB_Creatable = False
  85. Attribute VB_PredeclaredId = True
  86. Attribute VB_Exposed = False
  87. Private Sub Command1_Click()
  88.     Static URL As String
  89.     If URL = "" Then
  90.         URL = InputBox("Please enter a URL to parse elements:", "Enter URL", "http://www.alphamedia.net")
  91.     Else
  92.         URL = InputBox("Please enter a URL to parse elements:", "Enter URL", URL)
  93.     End If
  94.     If StrPtr(URL) = 0 Then GoTo Ending
  95.     Command1.Enabled = False
  96.     GetLinks (URL)
  97. Ending:
  98.     Command1.Enabled = True
  99. End Sub
  100. Sub GetLinks(URL As String)
  101.    On Error GoTo ErrPoint
  102.    Dim Web As New SHDocVw.InternetExplorer
  103.    Dim Doc As New MSHTML.HTMLDocument
  104.    Dim e As MSHTML.HTMLGenericElement
  105.    Dim a As MSHTML.HTMLAnchorElement
  106.    Dim i As MSHTML.HTMLImg
  107.    Dim t As MSHTML.HTMLTitleElement
  108.    Dim S As MSHTML.HTMLInputElement
  109.       
  110.    Call ResetTreeView
  111.    Web.navigate URL
  112.    Do While Web.Busy
  113.     DoEvents
  114.    Loop
  115.    Set Doc = Web.document
  116.    For Each e In Doc.All
  117.       If e.tagName = "A" Then
  118.          Set a = e
  119.          If a.href <> "" Then Call AddToTreeView(a.href, "A", 2)
  120.       ElseIf e.tagName = "IMG" Then
  121.          Set i = e
  122.          If i.src <> "" Then Call AddToTreeView(i.src, "IMG", 3)
  123.       ElseIf e.tagName = "TITLE" Then
  124.          Set t = e
  125.          If t.Text <> "" Then Call AddToTreeView("<TITLE>: " & t.Text, "Doc", 4)
  126.       ElseIf e.tagName = "INPUT" Then
  127.          Set S = e
  128.          If S.Name <> "" Then Call AddToTreeView("Name (" & S.Name & ")   Size (" & S.Size & ")   Value(" & S.Value & ")", "INPUT", 5)
  129.       End If
  130.    Next
  131. ErrPoint:
  132.    Call CountThem
  133.    Set Web = Nothing
  134. End Sub
  135. Sub CountThem()
  136.     Dim X As Integer
  137.     For X = 1 To 4
  138.         tv.Nodes(X).Text = tv.Nodes(X).Text & " (" & tv.Nodes(X).children & ")"
  139.     Next
  140. End Sub
  141. Private Sub Form_Load()
  142.     Height = 5000
  143.     Width = 5000
  144.     Call ResetTreeView
  145. End Sub
  146. Sub AddToTreeView(mText As String, mParent As String, Optional mImage As Integer)
  147.     On Error GoTo ErrPoint
  148.     Dim tvNode As Node
  149.     If mImage = 0 Then
  150.         Set tvNode = tv.Nodes.Add(mParent, tvwChild, Right(mText, 20), mText)
  151.     Else
  152.         Set tvNode = tv.Nodes.Add(mParent, tvwChild, Right(mText, 20), mText, mImage)
  153.     End If
  154. ErrPoint:
  155. End Sub
  156. Sub ResetTreeView()
  157.     tv.Nodes.Clear
  158.     Dim tvNode As Node
  159.     Set tvNode = tv.Nodes.Add(, tvwparent, "Doc", "Document Elements", 1)
  160.     Set tvNode = tv.Nodes.Add(, tvwparent, "A", "A's", 1)
  161.     Set tvNode = tv.Nodes.Add(, tvwparent, "IMG", "IMG's", 1)
  162.     Set tvNode = tv.Nodes.Add(, tvwparent, "INPUT", "INPUT's", 1)
  163. End Sub
  164. Private Sub Form_Resize()
  165.     On Error GoTo ErrPoint
  166.     List1.Move 0, 0, ScaleWidth, ScaleHeight - (Command1.Height + 150)
  167.     tv.Move 0, 0, ScaleWidth, ScaleHeight - (Command1.Height + 150)
  168.     Command1.Move ScaleWidth / 2 - Command1.Width / 2, ScaleHeight - (Command1.Height + 120)
  169. ErrPoint:
  170. End Sub
  171.