2014-11-21 58 views
0

嗨,大家好我需要litlle幫助。我有一些網頁,這條線在他的html:VBS HTML抽取線

<h3 class="entity-title"><a name="33333" class="link" href="/xy/xy-33333">some text</a></h3> 

我想的VBScript其打開網頁,找到這一行和「/ XY/XY-33333」複製到一些字符串變量。名,href和一些文字總是隨機

我有這樣的一部分(保存所有的HTML FILE.TXT)

Dim oXMLHTTP 
Dim oStream 

Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0") 

oXMLHTTP.Open "GET", "http://www.yyy.com", False 
oXMLHTTP.Send 

If oXMLHTTP.Status = 200 Then 
    Set oStream = CreateObject("ADODB.Stream") 
    oStream.Open 
    oStream.Type = 1 
    oStream.Write oXMLHTTP.responseBody 
    oStream.SaveToFile "c:\te\file.txt" 
    oStream.Close 
End If 

回答

1

嘗試是這樣的:

... 

If oXMLHTTP.Status = 200 Then 
    Set html = CreateObject("HTMLfile") 
    html.write oXMLHTTP.responseText 
    For Each h3 In html.getElementsByTagName("h3") 
    If h3.getAttribute("class") = "entity-title" Then 
     For Each a In h3.getElementsByTagName("a") 
     WScript.Echo a.href 
     Next 
    End If 
    Next 
End If 
+0

你的答案,但它感謝不完整的解決方案。我只需要類「實體標題」和這個代碼獲得所有h3類。有可能獲得特定的課程嗎? – 2014-11-24 23:15:43

+0

@josiplegionares只需過濾具有該值的'class'屬性的元素即可。查看更新的答案。 – 2014-11-25 09:34:21

+0

謝謝,我只需要將「class」更改爲「className」。它現在有效 – 2014-11-25 23:33:39