【问题标题】:How can i parse html description meta with classic asp xmlhttp我如何使用经典的 asp xmlhttp 解析 html 描述元
【发布时间】:2017-06-27 16:26:21
【问题描述】:

我使用经典代码解析 html 描述元是:

HTML 示例:

<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" />

我的代码不起作用。有没有办法两边都跑?正则表达式或在我的路上。

谢谢

【问题讨论】:

    标签: html regex asp-classic regexp-like


    【解决方案1】:
    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
    

    【讨论】:

      【解决方案2】:

      你可以试试这样的:

      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多