假设抓取到的网页内容如下:<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<html>
<head>
<title>
研究生院信息系统
-&gt;
查看考试成绩</title>    <link href="/media/default/css/default.css" rel="stylesheet" type="text/css">
    <link href="/media/default/css/customize.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="/js/css_expression.js"></script>
<script language="JavaScript" src="/js/util.js"></SCRIPT>
<script language="JavaScript" src="/js/usecalendar.js"></SCRIPT>    <script language="JavaScript" src="/js/customize.js"></script></head>
<body>
<br>
<br>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" class="list_RoundTitle" title="查看考试成绩"><tr>
    <td width="20%">学号:
    1111111111
    </td>
    <td width="15%">姓名:
    张三
    </td>
    <td>课程编号:
    0000001
    </td>
</tr></table>
<table cellpadding="0" cellspacing="0" border="0" width="98%" align="center">
<tr>
    <td align="top">
    
        
        
           <!-- 显示找到结果  -->
           
<table width="100%" cellpadding="4" class="list_caption_change_mouse" align="center" cellspacing="1" border="0" id="row">
<thead>
<tr>
<th width="7%" class="sortable" align="left">
<a href="queryDepartmentAction.do?d-16544-s=0&amp;studentid=xdleess20120514sn0727&amp;degreecourseno=0022001&amp;d-16544-o=2&amp;d-16544-p=1">上课学期</a></th>
<th width="16%" class="sortable" align="left">
<a href="queryDepartmentAction.do?d-16544-s=1&amp;studentid=xdleess20120514sn0727&amp;degreecourseno=0022001&amp;d-16544-o=2&amp;d-16544-p=1">课程名称</a></th>
<th width="4%" class="sortable" align="left">
<a href="queryDepartmentAction.do?d-16544-s=2&amp;studentid=xdleess20120514sn0727&amp;degreecourseno=0022001&amp;d-16544-o=2&amp;d-16544-p=1">学分</a></th>
<th width="14%" class="sortable" align="left">
<a href="queryDepartmentAction.do?d-16544-s=3&amp;studentid=xdleess20120514sn0727&amp;degreecourseno=0022001&amp;d-16544-o=2&amp;d-16544-p=1">任课教师</a></th>
<th width="7%" class="sortable" align="left">
<a href="queryDepartmentAction.do?d-16544-s=4&amp;studentid=xdleess20120514sn0727&amp;degreecourseno=0022001&amp;d-16544-o=2&amp;d-16544-p=1">总评成绩</a></th>
<th width="7%" class="sortable" align="left">
<a href="queryDepartmentAction.do?d-16544-s=5&amp;studentid=xdleess20120514sn0727&amp;degreecourseno=0022001&amp;d-16544-o=2&amp;d-16544-p=1">获得学分</a></th>
<th width="14%" class="sortable" align="left">
<a href="queryDepartmentAction.do?d-16544-s=6&amp;studentid=xdleess20120514sn0727&amp;degreecourseno=0022001&amp;d-16544-o=2&amp;d-16544-p=1">备注</a></th></tr></thead>
<tbody>
<tr class="odd">
<td width="7%" align="left">2012秋</td>
<td width="16%" align="left">
                    体育课                    </td>
<td width="4%" align="left">0.5</td>
<td width="14%" align="left">李四</td>
<td width="7%" align="left">
                        
                            
                                96.0
                            
                        
                    </td>
<td width="7%" align="left">
                        
                            0.5
                        
                    </td>
<td width="14%" align="left">
                        
                       
                       
                    </td></tr></tbody></table><span class="pagebanner">共找到<font color="#FF0000"> 1 </font>条记录.</span><span class="pagelinks"></span>
        
        
        </td>
</tr>
</table>想把<tr class="odd"></tr>里面的内容(包括“体育课”和“96”等)提取出来,该如何实现呢?

解决方案 »

  1.   

    不知道你具体的需求,简单的想法截取字符串
    <tbody>开始到</tbody>结束,然后用XmlDocument的loadxml方法加载内容作为一个标准的xml处理,然后就可以用xpath找到你想要的数据了web直接jquery了,简单的要死了
      

  2.   

    http://zhoufoxcn.blog.51cto.com/792419/595344
      

  3.   


    string start = "<tbody>";
    int indexStart = str.IndexOf(start);
    string end = "</tbody>";
    int indexEnd = str.IndexOf(end);
    int length = indexEnd - indexStart;
    string s2 = str.Substring(indexStart, length);
    MessageBox.Show(s2);