2017-06-27 2 views
1

j'ai en utilisant le code classique avec méta Parse html desctiption est:Comment puis-je analyser la description html meta XMLHTTP asp classique

Html exaple:

<meta name="keywords" content="Software AG, Altenkesseler Straße 17, Saarbrücken, Saarland, software ag, Ofis" /> 

Code de Parse:

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) 

c'est un travail mais lorsque le code html change l'emplacement des écritures par exemple:

<meta content="Software AG, Altenkesseler Straße 17, Saarbrücken, Saarland, software ag, Ofis" name="keywords" /> 

cela ne fonctionne pas mon code. Y a-t-il un moyen de courir des deux côtés? regex ou sur mon chemin.

merci

Répondre

0
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 
0

vous pouvez essayer quelque chose comme ceci:

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