2013-07-09 62 views
-2

我正在使用以下經典ASP代碼從網頁之一提取內容。正則表達式提取HTML下拉標記 - 經典ASP

該網頁有一個選擇框,我想要做的是顯示,只有在效應初探選擇框,所以不知道我應該怎麼改變這裏strPattern = "<select>(.*?)<\/select>"

HTML下拉代碼,我需要訪問

<select onchange="change_option('SELECT___MC-TRIMC350___56',this.options[this.selectedIndex].value)" name="SELECT___MC-TRIMC350___56" class=" PIN_1373378891415_hazClick"> 
<option value="634">1 GAL [$64.99]</option> 
<option value="629" class=" PIN_1373378891415_hazClick">5 GAL PAIL [$144.99]</option> 
<option value="637">54 GAL DRUM [$2,225.00]</option> 
</select> 

讀取頁面標題經典ASP代碼,我希望它改變,從而顯示選擇框,因爲它是

Dim strURL, objXMLHTTP, objXML, strContents 
Dim objRegExp, strHTML, strPattern, colMatches, strTitle 

strURL= "http://abc.com/testhtm" 


Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP") 
'Or if this doesn't work then try : 
'Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP") 

objXMLHTTP.Open "GET", strURL, False 

objXMLHTTP.Send 

strContents = objXMLHTTP.ResponseText 

Set objXMLHTTP = Nothing 

Set objRegExp = New RegExp 

strPattern = "<select>(.*?)<\/select>" 

objRegExp.Pattern = strPattern 
objRegExp.IgnoreCase = True 
objRegExp.Global = True 

Set colMatches = objRegExp.Execute(strContents) 

If colMatches.Count > 0 then 
    strTitle = objMatches(0).Value 
Else 
    strTitle = "" 
End If 

Set objRegExp = Nothing 

Response.write(strTitle) 

回答

2

<select.*>[\w\W]*<\/select>

我不知道,如果.以捕捉換行符在傳統的ASP,所以我選擇了\w\W代替。你需要和>.*之間<select跳過過去的HTML屬性(onchange等)

UPDATE: 你在代碼中有一個錯誤。您從未設置或聲明objMatches。您應該改用colMatches

If colMatches.Count > 0 Then 
    strTitle = colMatches(0).Value 
Else 
    strTitle = "" 
End If 
+0

我試圖犯規顯示任何 – user580950

+1

試試我的更新..你的幫助我的朋友 – basher

+0

十分感謝:) – user580950