2012-01-19 22 views
1

我正在尋找匹配傳入ASP文件中的循環的幾個HTML文件的一部分,然後返回HTML文件的部分以包含在我的輸出。這裏是我的代碼到目前爲止:如何匹配並返回ASP文件中的HTML文件的一部分

<%for i=0 to uBound(fileIDs) ' fileIDs is an array of URLs 
    dim srcText, outText, url 
    Set ex = New RegExp 
    ex.Global = true 
    ex.IgnoreCase = true 
    ex.Pattern = "<section>[\S\s]+</section>" ' This finds the HTML I want 
    url = fileIDs(i) 
    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 
    xmlhttp.open "GET", url, false 
    xmlhttp.send "" 
    srcText = xmlhttp.responseText 
    outputText = ex.Execute(mediaSrcText) ' I expect this to be the HTML I want 
    Response.Write(outputText.Item(0).Value) ' This would then return the first instance 
    set xmlhttp = nothing 
next %> 

我測試了我的文件的正則表達式,它匹配我想要它的部分。

當我運行包含此代碼的網頁,我得到一個錯誤:

Microsoft VBScript runtime error '800a01b6' 
Object doesn't support this property or method 

與ex.Execute行了。我也試過ex.Match,但得到了同樣的錯誤。所以我顯然缺少返回匹配的正確方法,所以我可以將它寫入文件中。那是什麼方法?還是我從錯誤的方向接近問題?

謝謝!

回答

1

你需要一個Set,當你分配outputText

Set outputText = ex.Execute(mediaSrcText) 

我可能也說,你真的不應該使用正則表達式試圖解析HTML,但我不知道夠不夠被關於上下文提供更具體的建議。

+0

謝謝!這讓我至少前進到一個新的錯誤。繼續! – theJBRU

+0

可悲的是,我目前無法訪問傳統的ASP環境,否則我可能會更進一步:-) – Anodyne

相關問題