有没有一种方法可以通过VBScript遍历html网页上的所有元素?

有没有一种方法可以通过VBScript遍历html网页上的所有元素?,vbscript,Vbscript,有没有一种方法可以通过VBScript遍历html网页上的所有元素?例如,我想获取html网页上的所有对象信息: 以下是我创建的脚本,谢谢: Dim objIE Dim IEObject Dim Info Info = “” Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True objIE.Navigate "http://www.echoecho.com/html.htm" Do Whi

有没有一种方法可以通过VBScript遍历html网页上的所有元素?例如,我想获取html网页上的所有对象信息:

以下是我创建的脚本,谢谢:

Dim objIE 
Dim IEObject
Dim Info
Info = “”

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "http://www.echoecho.com/html.htm"

Do While objIE.Busy Or (objIE.READYSTATE <> 4)
   Wscript.Sleep 100
Loop
WScript.Sleep 50

‘ Can I use objIE.Document.all.Item.length to count all elements on the webpage?
For i=1 to objIE.Document.all.Item.length then

   IEObject = objIE.Document..??????... item (i-1)…???
   Info = Info & vbCrLf & i & IEObject.id & “-“IEObject.title & “-“ & IEObject.name & “-“ & ….etc.

Next

Wscript.Echo Info

Set IEObject = Nothing
Set objIE = Nothing

你的问题有点含糊,但我相信这会奏效:

Dim objIE, IEObject, Info, all, hasOwnProperty
Info = ""

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "http://www.echoecho.com/html.htm"

Do While objIE.Busy Or (objIE.READYSTATE <> 4)
 Wscript.Sleep 100
Loop
WScript.Sleep 50

Set hasOwnProperty = objIE.Document.ParentWindow.Object.prototype.hasOwnProperty

' Can I use objIE.Document.all.Item.length to count all elements on the webpage?
Set all = objIE.Document.all
For i = 0 To all.Item.Length - 1
Set IEObject = all.Item(i)

'If this is not the first item, place this data on a new line.
If i > 0 Then Info = Info & vbCrLf

' Number each line.
Info = Info & i + 1 & ". "

' Specify the ID if it is given.
If hasOwnProperty.call(IEObject, "id") Then
  Info = Info & IEObject.id
Else
  Info = Info & "[NO ID]"
End If

' Specify the title if it is given.
If hasOwnProperty.call(IEObject, "title") Then
  Info = Info & "-" & IEObject.title
Else
  Info = Info & "-[NO TITLE]"
End If

' Specify the name if it is given.
If hasOwnProperty.call(IEObject, "name") Then
  Info = Info & "-" & IEObject.name
Else
  Info = Info & "-[NO NAME]"
End If
Next

Wscript.Echo Info

Set IEObject = Nothing
Set objIE = Nothing
您会注意到,我正在使用hasOwnProperty函数来检查给定元素的指定属性是否实际存在。如果不进行此检查,错误将出现在VBScript中,而不会出现在JScript中