[英]How can i parse html description meta with classic asp xmlhttp
我使用經典代碼與解析html desctiption元是:
Html exaple:
<meta name="keywords" content="Software AG, Altenkesseler Straße 17, Saarbrücken, Saarland, software ag, Ofis" />
解析代碼:
Baslangic = InStr(1,sdata,"<meta name=" & Chr(34) & "keywords" & Chr(34), 1) + Len("<meta name=" & Chr(34) & "keywords" & Chr(34))
Baslangic = InStr(Baslangic,sdata,Chr(34),1)+1
Genislik = InStr(Baslangic,sdata,Chr(34),1) - Baslangic
KeywordAl= Mid(sdata, Baslangic, Genislik)
這是工作,但當html代碼更改文字的位置,例如:
<meta content="Software AG, Altenkesseler Straße 17, Saarbrücken, Saarland, software ag, Ofis" name="keywords" />
它不起作用我的代碼。 有沒有辦法在兩邊跑? 正則表達式或在我的路上。
謝謝
if (instr(1, sdata,"<meta ", 1)=1 and instr(7, sdata, "name=""keywords""", 1)>6) then
Set regEx = New RegExp
regEx.Pattern = "content=""(.+?)"""
regEx.IgnoreCase = True
Set matches = regEx.Execute(sdata)
if matches.Count > 0 then
KeywordAl = matches(0).SubMatches(0)
end if
end if
你可以嘗試這樣的事情:
meta = "<meta name=""keywords"" content=""Software AG, Altenkesseler Straße 17, Saarbrücken, Saarland, software ag, Ofis"" />"
if InStr( meta, "content=" ) > 0 then
arrMeta = Split( meta, "content=" )
keywords = arrMeta( 1 ) ''-- your data will be in the 2nd row of the array
keywords = Trim( Replace( Replace( Replace( keywords, """", "" ), "/>", "" ), "name=keywords", "" ) )
end if
Response.Write keywords
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.