最近想编写一个自动查询成绩的小程序
我用webbowser自动登入,然后转到成绩查询的页面,将网页源代码赋给了一个字符串变量,想提取其中的表格内容到一个listview(或其它方便的能够显示表格的控件)中显示,应该如何做呢?网页代码如下(由于字数限制精简过内容,但不影响结构)
只提取学期(不在table内)、课程名、学分和分数<html>
<head>
<link rel="stylesheet" type="text/css" href="/css/newcss/project.css">
</head>
<body style="OVERFLOW: auto" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<a name="2011-2012学年秋(两学期)"></a>
<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
<tbody>
<tr>
<td class="Linetop"></td>
</tr>
</tbody>
</table>
<table id="tblHead" class="title" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td width="80%">
<table cellspacing="0" cellpadding="0" align="left" border="0">
<tbody>
<tr>
<td> </td>
<td valign="middle"> <b>2011-2012学年秋(两学期)</b> </td>
</tr>
</tbody>
</table>
</td>
<td width="20%">
<table cellspacing="0" cellpadding="0" width="100%" align="left" border="0">
<tbody>
<tr>
<td> </td>
<td width="5"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
<tbody>
<tr>
<td class="Linetop"></td>
</tr>
</tbody>
</table>
<table class="titleTop2" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td class="pageAlign">
<table id="user" class="displayTag" cellspacing="1" cellpadding="0" width="100%" border="0">
<thead>
<tr>
<th class="sortable" width="10%" align="center">课程号 </th>
<th class="sortable" width="10%" align="center">课序号 </th>
<th class="sortable" width="10%" align="center">课程名 </th>
<th class="sortable" width="10%" align="center">英文课程名 </th>
<th class="sortable" width="10%" align="center">学分 </th>
<th class="sortable" width="10%" align="center">课程属性 </th>
<th class="sortable" width="10%" align="center">成绩 </th>
</tr>
</thead>
<tbody>
<tr onmouseover="this.className='evenfocus';" onmouseout="this.className='even';" class="even">
<td align="center">10720804 </td>
<td align="center">10 </td>
<td align="center">大学英语一级(A) </td>
<td align="center"> </td>
<td align="center">4 </td>
<td align="center">必修 </td>
<td align="center">
<p align="center">83.0 </p>
</td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" width="100%" align="center">
<tbody>
<tr>
<td height="21">最低修读学分: 25.0 已修读课程总学分: 4.0 已修读课程门数: 1 通过课程门数: 1 </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<a name="2012-2013学年秋(两学期)"></a>
<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
<tbody>
<tr>
<td class="Linetop"></td>
</tr>
</tbody>
</table>
<table id="TABLE7" class="title" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td width="80%">
<table cellspacing="0" cellpadding="0" align="left" border="0">
<tbody>
<tr>
<td> </td>
<td valign="middle"> <b>2012-2013学年秋(两学期)</b> </td>
</tr>
</tbody>
</table>
</td>
<td width="20%">
<table cellspacing="0" cellpadding="0" width="100%" align="left" border="0">
<tbody>
<tr>
<td> </td>
<td width="5"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
<tbody>
<tr>
<td class="Linetop"></td>
</tr>
</tbody>
</table>
<table class="titleTop2" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td class="pageAlign">
<table id="TABLE8" class="displayTag" cellspacing="1" cellpadding="0" width="100%" border="0">
<thead>
<tr>
<th class="sortable" width="10%" align="center">课程号 </th>
<th class="sortable" width="10%" align="center">课序号 </th>
<th class="sortable" width="10%" align="center">课程名 </th>
<th class="sortable" width="10%" align="center">英文课程名 </th>
<th class="sortable" width="10%" align="center">学分 </th>
<th class="sortable" width="10%" align="center">课程属性 </th>
<th class="sortable" width="10%" align="center">成绩 </th>
</tr>
</thead>
<tbody>
<tr onmouseover="this.className='evenfocus';" onmouseout="this.className='even';" class="odd">
<td align="center">11610204 </td>
<td align="center">04 </td>
<td align="center">数据结构 </td>
<td align="center"> </td>
<td align="center">4 </td>
<td align="center">任选 </td>
<td align="center">
<p align="center">85.0 </p>
</td>
</tr>
<tr onmouseover="this.className='evenfocus';" onmouseout="this.className='even';" class="odd">
<td align="center">12200031 </td>
<td align="center">60 </td>
<td align="center">体育(三) </td>
<td align="center">Physical education </td>
<td align="center">1 </td>
<td align="center">任选 </td>
<td align="center">
<p align="center">83.0 </p>
</td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" width="100%" align="center">
<tbody>
<tr>
<td height="21">最低修读学分: 25.0 已修读课程总学分: 12.0 已修读课程门数: 10 通过课程门数: 4 </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
listviewhtml
我用webbowser自动登入,然后转到成绩查询的页面,将网页源代码赋给了一个字符串变量,想提取其中的表格内容到一个listview(或其它方便的能够显示表格的控件)中显示,应该如何做呢?网页代码如下(由于字数限制精简过内容,但不影响结构)
只提取学期(不在table内)、课程名、学分和分数<html>
<head>
<link rel="stylesheet" type="text/css" href="/css/newcss/project.css">
</head>
<body style="OVERFLOW: auto" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<a name="2011-2012学年秋(两学期)"></a>
<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
<tbody>
<tr>
<td class="Linetop"></td>
</tr>
</tbody>
</table>
<table id="tblHead" class="title" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td width="80%">
<table cellspacing="0" cellpadding="0" align="left" border="0">
<tbody>
<tr>
<td> </td>
<td valign="middle"> <b>2011-2012学年秋(两学期)</b> </td>
</tr>
</tbody>
</table>
</td>
<td width="20%">
<table cellspacing="0" cellpadding="0" width="100%" align="left" border="0">
<tbody>
<tr>
<td> </td>
<td width="5"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
<tbody>
<tr>
<td class="Linetop"></td>
</tr>
</tbody>
</table>
<table class="titleTop2" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td class="pageAlign">
<table id="user" class="displayTag" cellspacing="1" cellpadding="0" width="100%" border="0">
<thead>
<tr>
<th class="sortable" width="10%" align="center">课程号 </th>
<th class="sortable" width="10%" align="center">课序号 </th>
<th class="sortable" width="10%" align="center">课程名 </th>
<th class="sortable" width="10%" align="center">英文课程名 </th>
<th class="sortable" width="10%" align="center">学分 </th>
<th class="sortable" width="10%" align="center">课程属性 </th>
<th class="sortable" width="10%" align="center">成绩 </th>
</tr>
</thead>
<tbody>
<tr onmouseover="this.className='evenfocus';" onmouseout="this.className='even';" class="even">
<td align="center">10720804 </td>
<td align="center">10 </td>
<td align="center">大学英语一级(A) </td>
<td align="center"> </td>
<td align="center">4 </td>
<td align="center">必修 </td>
<td align="center">
<p align="center">83.0 </p>
</td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" width="100%" align="center">
<tbody>
<tr>
<td height="21">最低修读学分: 25.0 已修读课程总学分: 4.0 已修读课程门数: 1 通过课程门数: 1 </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<a name="2012-2013学年秋(两学期)"></a>
<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
<tbody>
<tr>
<td class="Linetop"></td>
</tr>
</tbody>
</table>
<table id="TABLE7" class="title" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td width="80%">
<table cellspacing="0" cellpadding="0" align="left" border="0">
<tbody>
<tr>
<td> </td>
<td valign="middle"> <b>2012-2013学年秋(两学期)</b> </td>
</tr>
</tbody>
</table>
</td>
<td width="20%">
<table cellspacing="0" cellpadding="0" width="100%" align="left" border="0">
<tbody>
<tr>
<td> </td>
<td width="5"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
<tbody>
<tr>
<td class="Linetop"></td>
</tr>
</tbody>
</table>
<table class="titleTop2" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td class="pageAlign">
<table id="TABLE8" class="displayTag" cellspacing="1" cellpadding="0" width="100%" border="0">
<thead>
<tr>
<th class="sortable" width="10%" align="center">课程号 </th>
<th class="sortable" width="10%" align="center">课序号 </th>
<th class="sortable" width="10%" align="center">课程名 </th>
<th class="sortable" width="10%" align="center">英文课程名 </th>
<th class="sortable" width="10%" align="center">学分 </th>
<th class="sortable" width="10%" align="center">课程属性 </th>
<th class="sortable" width="10%" align="center">成绩 </th>
</tr>
</thead>
<tbody>
<tr onmouseover="this.className='evenfocus';" onmouseout="this.className='even';" class="odd">
<td align="center">11610204 </td>
<td align="center">04 </td>
<td align="center">数据结构 </td>
<td align="center"> </td>
<td align="center">4 </td>
<td align="center">任选 </td>
<td align="center">
<p align="center">85.0 </p>
</td>
</tr>
<tr onmouseover="this.className='evenfocus';" onmouseout="this.className='even';" class="odd">
<td align="center">12200031 </td>
<td align="center">60 </td>
<td align="center">体育(三) </td>
<td align="center">Physical education </td>
<td align="center">1 </td>
<td align="center">任选 </td>
<td align="center">
<p align="center">83.0 </p>
</td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" width="100%" align="center">
<tbody>
<tr>
<td height="21">最低修读学分: 25.0 已修读课程总学分: 12.0 已修读课程门数: 10 通过课程门数: 4 </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
listviewhtml
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货