2

I have a HTML document of the structure

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

I want to extract the contents of the tag of lines 1,2,3,4 and save to a string. I want to know how to achieve this using Majestic13 in my C# project.

4

1 回答 1

-1

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);
于 2012-08-07T04:42:20.783 回答