2010-05-21 5 views
1

VBScript를 통해 HTML 웹 페이지의 모든 요소를 ​​트래버스하는 방법이 있습니까? 여기VBScript를 통해 HTML 웹 페이지의 모든 요소를 ​​트래버스하는 방법이 있습니까?

http://www.echoecho.com/html.htm 내가 만든 스크립트입니다 감사 : 예를 들어, 나는 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 

답변

0

당신의 질문이 조금 애매을,하지만 난 믿을 트릭을 할 것입니다 :

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에서는 오류가 발생하지 않습니다.

관련 문제