首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

VB6.0 怎么提取上面源码中<td></td>之间的字符串

2012-07-30 
VB6.0 如何提取下面源码中td/td之间的字符串table border0 cellpadding0 cellspacing0col

VB6.0 如何提取下面源码中<td></td>之间的字符串
<table border="0" cellpadding="0" cellspacing="0">
  <colgroup>
  <col class="col-par" />
  <col class="col-scope" />
  <col class="col-owner" />
  <col class="col-status" />
  <col class="col-expired" />
  </colgroup>
  <thead>
  <tr class="ui-thead-grade">
  <th>级别</th>
  <th>类型</th>
  <th>验证人</th>
  <th>状态</th>
  <th>截止日期</th>
  </tr>
  </thead>
  <tbody>
<tr>
<td>3</td>
<td>新成员</td>
<td>踩气球的故事</td>
<td>未验证</td>
<td>2012-06-30</td>
  </tr>
<tr>
<td>3</td>
<td>新成员</td>
<td>微信生活</td>
<td>未验证</td>
<td>2012-06-30</td>
  </tr>
<tr>
<td>3</td>
<td>新成员</td>
<td>警卫艾米</td>
<td>未验证</td>
<td>2012-06-30</td>
  </tr>
<tr>
<td>3</td>
<td>新成员</td>
<td>华夏满堂红1</td>
<td>未验证</td>
<td>2012-06-30</td>
  </tr>
<tr>
<td>3</td>
<td>新成员</td>
<td>警卫艾米</td>
<td>未验证</td>
<td>2012-06-30</td>
  </tr>
<tr>
<td>3</td>
<td>新成员</td>
<td>华夏满堂红1</td>
<td>未验证</td>
<td>2012-06-30</td>
  </tr>
<tr>
<td>3</td>
<td>新成员</td>
<td>华夏满堂红1</td>
<td>未验证</td>
<td>2012-06-30</td>


  </tr>
<tr>
<td>3</td>
<td>新成员</td>
<td>警卫艾米</td>
<td>未验证</td>
<td>2012-06-30</td>
  </tr>
<tr>
<td>3</td>
<td>新成员</td>
<td>华夏满堂红1</td>
<td>未验证</td>
<td>2012-06-30</td>
  </tr>
<tr>
<td>3</td>
<td>新成员</td>
<td>警卫艾米</td>
<td>未验证</td>
<td>2012-06-30</td>
  </tr>
</tbody>
  <tfoot>
  <tr>
  <td colspan="5">
  <div class="pagination">
  <div class="page-bottom">
<script type="text/javascript">
var max_pages = 4
;
var current_page = 3
;

我想提取以上源码中的内容指定<td></td>之间的字符串。每个<tr></tr>中包含5组<td></td>字符串,我想提取的是第三组<td></td>之间的字符串 请高手给出一个代码 谢谢了 
我是纯小白 没有文化 希望能注释下 非常感谢!

[解决办法]

VB code
Option Explicit                                                                 Private Sub Command1_Click()    Dim tem$    tem = " cellpadding=""0"" cellspacing=""0"">" & _          "  <colgroup>" & _          "  <col class=""col-par"" />" & _          "  <col class=""col-scope"" />" & _          "  <col class=""col-owner"" />" & _          "  <col class=""col-status"" />" & _          "  <col class=""col-expired"" />" & _          "  </colgroup>" & _          "  <thead>" & _          "  <tr class=""ui-thead-grade"">" & _          "  <th>级别</th>" & _          "  <th>类型</th>" & _          "  <th>验证人</th>" & _          "  <th>状态</th>" & _          "  <th>截止日期</th>" & _          "  </tr>"    tem = tem & "  </thead>" & _          "  <tbody>" & _          "<tr>" & _          "<td>3</td>" & _          "<td>新成员</td>" & _          "<td>踩气球的故事</td>" & _          "<td>未验证</td>" & _          "<td>2012-06-30</td>" & _          "  </tr>" & _          "<tr>" & _          "<td>3</td>" & _          "<td>新成员</td>" & _          "<td>微信生活</td>" & _          "<td>未验证</td>" & _          "<td>2012-06-30</td>" & _          "  </tr>" & _          "<tr>"    tem = tem & "<td>3</td>" & _          "<td>新成员</td>" & _          "<td>警卫艾米</td>" & _          "<td>未验证</td>" & _          "<td>2012-06-30</td>" & _          "  </tr>" & _          "<tr>" & _          "<td>3</td>" & _          "<td>新成员</td>" & _          "<td>华夏满堂红1</td>" & _          "<td>未验证</td>" & _          "<td>2012-06-30</td>" & _          "  </tr>" & _          "<tr>" & _          "<td>3</td>" & _          "<td>新成员</td>" & _          "<td>警卫艾米</td>" & _          "<td>未验证</td>" & _          "<td>2012-06-30</td>" & _          "  </tr>" & _          "<tr>"    tem = tem & "<td>3</td>" & _          "<td>新成员</td>" & _          "<td>华夏满堂红1</td>" & _          "<td>未验证</td>" & _          "<td>2012-06-30</td>" & _          "  </tr>" & _          "<tr>" & _          "<td>3</td>" & _          "<td>新成员</td>" & _          "<td>华夏满堂红1</td>" & _          "<td>未验证</td>" & _          "<td>2012-06-30</td>" & _          "  </tr>" & _          "<tr>" & _          "<td>3</td>"    tem = tem & "<td>新成员</td>" & _          "<td>警卫艾米</td>" & _          "<td>未验证</td>" & _          "<td>2012-06-30</td>" & _          "  </tr>" & _          "<tr>" & _          "<td>3</td>" & _          "<td>新成员</td>" & _          "<td>华夏满堂红1</td>" & _          "<td>未验证</td>" & _          "<td>2012-06-30</td>" & _          "  </tr>" & _          "<tr>" & _          "<td>3</td>" & _          "<td>新成员</td>" & _          "<td>警卫艾米</td>" & _          "<td>未验证</td>"    tem = tem & "<td>2012-06-30</td>" & _          "  </tr>" & _          "</tbody>" & _          "  <tfoot>" & _          "  <tr>" & _          "  <td colspan=""5"">" & _          "  <div class=""pagination"">" & _          "  <div class=""page-bottom"">" & _          "<script type=""text/javascript"">" & _          "Var max_pages = 4" & _          ";" & _          "Var current_page = 3" & _          ";"    Call GetSource(tem)End Sub                                                                         Sub GetSource(ByVal Source$)    On Error Resume Next    Dim RegExp As Object, Matches As Object    Dim i&    Set RegExp = CreateObject("VBscript.RegExp")    RegExp.Global = True    RegExp.Pattern = "<tr>[\s\S]*?<td>(?:.*?)</td>[\s\S]*?<td>(?:.*?)</td>[\s\S]*?<td>(.*?)</td>[\s\S]*?<td>(?:.*?)</td>[\s\S]*?<td>(?:.*?)</td>[\s\S]*?  </tr>"    Set Matches = RegExp.Execute(Source)    For i = 0 To Matches.Count - 1        Debug.Print Matches(i).SubMatches(0)    Next i    Set RegExp = Nothing    Set Matches = NothingEnd Sub 


[解决办法]

VB code
Private Sub Form_Load()    Dim strData As String, s$    Dim reg As Object    Dim matchs As Object, match As Object    strData = "<tr>" & vbCrLf & _              "<td>3</td>" & vbCrLf & _              "<td>新成员</td>" & vbCrLf & _              "<td>警卫艾米</td>" & vbCrLf & _              "<td>未验证</td>" & vbCrLf & _              "<td>2012-06-30</td>" & vbCrLf & _              "  </tr>" & vbCrLf & _              "<tr>" & vbCrLf & _              "<td>3</td>" & vbCrLf & _              "<td>新成员</td>" & vbCrLf & _              "<td>华夏满堂红1</td>" & vbCrLf & _              "<td>未验证</td>" & vbCrLf & _              "<td>2012-06-30</td>" & vbCrLf & _              "  </tr>" & vbCrLf & _              "<tr>" & vbCrLf & _              "<td>3</td>" & vbCrLf & _              "<td>新成员</td>" & vbCrLf & _              "<td>警卫艾米</td>" & vbCrLf & _              "<td>未验证</td>" & vbCrLf & _              "<td>2012-06-30</td>"    Set reg = CreateObject("vbscript.regExp")    reg.Global = True    reg.IgnoreCase = True    reg.MultiLine = True    reg.Pattern = "<td>(.*?)</td>"    Set matchs = reg.Execute(strData)    For Each match In matchs        s = s & match.SubMatches(0) & IIf(IsDate(match.SubMatches(0)), vbCrLf, " ")    Next    Debug.Print sEnd Sub
[解决办法]
正则表达式速查 正则表达式举例 正则表达式学习 (4页A4纸)
http://download.csdn.net/detail/zhao4zhong1/1808549

热点排行