2011-01-28 45 views
0

網站我有拉出一個鏈接作爲獲取HTML響應到一個變量,現在我堅持:需要儘可能遠離使用VBScript

鏈接:http://www.avg.com/gb-en/31.prd-avb

在一個理想的世界,我會能夠獲得x86和x64的第一個和第二個鏈接。所有我需要的是exe文件的實際位置到一個變量:IE:

download.avg.com/filedir/inst/avg_ipw_x86_all_2011_1204a3402.exe

任何人都可以點我在正確的方向?

預先感謝任何幫助提供

回答

2

這工作,但它是遠離恆星的技術,因爲我parsing HTML with regex

但是,我沒有意識到在Classic ASP中實現這一點的更簡單的方法,並且這是一個簡單的任務。

<% 

url = "http://www.avg.com/gb-en/31.prd-avb" 

Dim http 
Set http = Server.CreateObject("WinHttp.WinHttpRequest.5.1") 
http.SetTimeouts 20000, 20000, 20000, 10000 
http.Open "GET", url, False 
http.Send 
If http.WaitForResponse(5) Then 
    responseText = http.ResponseText 
End If 
Set http = Nothing 

'Response.Write(Server.HtmlEncode(responseText)) 

Set re = New RegExp 
re.IgnoreCase = True 
re.Global = True 
re.Pattern = "<a href=""(http://download\.avg\.com/filedir/inst/.*?)""" 
Set matches = re.Execute(responseText) 
If matches.Count > 0 Then 
    For Each match In matches 
     Response.Write(match.SubMatches(0) & "<br />") 
    Next 
Else 
    Response.Write("No matches.") 
End If 

%> 

給出了這樣的輸出:

http://download.avg.com/filedir/inst/avg_ipw_x86_all_2011_1204a3402.exe 
http://download.avg.com/filedir/inst/avg_ipw_x64_all_2011_1204a3402.exe 
http://download.avg.com/filedir/inst/avg_msw_x86_all_2011_1204a3402.exe 
http://download.avg.com/filedir/inst/avg_msw_x64_all_2011_1204a3402.exe 
http://download.avg.com/filedir/inst/avg_rad_x86_all_2011_1154.exe 
http://download.avg.com/filedir/inst/avg_rad_x64_all_2011_1154.exe 
+0

這是極好的 - 謝謝。我研究了通過標籤進行解析,但是它們在表格中有點困難。再次感謝 – Trinitrotoluene 2011-01-28 01:56:00