我有一个结构的HTML文档

<table width="85%" border="1" height="315" align="center">
  <tr>
    <td colspan="2" align="center"><font color="#400040"><b>Register No</b></font></td>
    <th colspan="2"><font color="Brown">42209104069</font></th>
    <td colspan="2" align="center"><font color="#400040"><b>Name</b></font></td>
    <th colspan="2"><font color="Brown">SATHISH KUMAR R</font></th>
  </tr>
  <tr>
    <td colspan="2"><font color="blue"><center><b>Subject</b></font></td>
    <td colspan="2"><font color="blue"><center><b>Credits</b></font></td>
    <td colspan="2"><font color="blue"><center><b>Grade</b></font></td>
    <td colspan="2"><font color="blue"><center><b>Result</b></font></td>
  </tr>
  <tr>
    <td colspan="2"><center> CS2301</td> //1
    <td colspan="2"><center> 3</td>      //2
    <td colspan="2"><center> E</td>      //3
    <td colspan="2"><center> PASS</td>   //4
  </tr>
</table>

我要提取第1、2、3、4行标记的内容并保存到字符串中。我想知道如何在我的C项目中使用Majestic13来实现这一点。

最佳答案

PM>安装Majestic13包

    var html=@"<table width="85%" border="1" height="315" align="center">
  <tr>
    <td colspan="2" align="center"><font color="#400040"><b>Register No</b></font></td>
    <th colspan="2"><font color="Brown">42209104069</font></th>
    <td colspan="2" align="center"><font color="#400040"><b>Name</b></font></td>
    <th colspan="2"><font color="Brown">SATHISH KUMAR R</font></th>
  </tr>
  <tr>
    <td colspan="2"><font color="blue"><center><b>Subject</b></font></td>
    <td colspan="2"><font color="blue"><center><b>Credits</b></font></td>
    <td colspan="2"><font color="blue"><center><b>Grade</b></font></td>
    <td colspan="2"><font color="blue"><center><b>Result</b></font></td>
  </tr>
  <tr>
    <td colspan="2" class="a"><center> CS2301</td> //1
    <td colspan="2" class="a"><center> 3</td>      //2
    <td colspan="2" class="a"><center> E</td>      //3
    <td colspan="2" class="a"><center> PASS</td>   //4
  </tr>
</table>";

        var paser = new HtmlParser();
        var node = paser.Pasrse(html);
        var finder = new FindTagsVisitor(TagBuilder => tag.Name == "td" && tag.Attributes.ContainsKey("class"));
        node.AcceptVisitor(finder);

10-07 18:11