利用WebBrowser读取网页中报表的数据(已有大部分代码,但读取失败)
利用WebBrowser读取网页中表格的数据(已有大部分代码,但读取失败)
比如这样一个网页:
我想读取里面的数据,利用下面一段代码,但一直提示“找不到表格”
附代码的出处:http://topic.csdn.net/t/20060920/09/5033996.html
比如这样一个网页:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<table class="zhangdan_table" width="100%">
<tbody>
<tr class="table_top">
<td width="16%">编号</td>
<td width="19%">班别</td>
<td width="10%">年龄 </td>
<td width="25%">姓名 </td>
<td width="30%">出生年月 </td>
</tr>
<tr class="table_li">
<td><b>001</b> </td>
<td>一(1)</td>
<td><span>¥20</span> </td>
<td>小明</td>
<td>2000-08-01 </td>
</tr>
</tbody>
</table>
</body>
</html>
我想读取里面的数据,利用下面一段代码,但一直提示“找不到表格”
附代码的出处:http://topic.csdn.net/t/20060920/09/5033996.html
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MSHTML, StdCtrls, OleCtrls, SHDocVw;
type
TForm1 = class(TForm)
Button1: TButton;
WebBrowser1: TWebBrowser;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetHtmlTableCell(aTable: IHTMLTable; aRow, aCol: Integer): IHTMLElement;
var
Row: IHTMLTableRow;
begin
Result := nil;
if aTable = nil then Exit;
if aTable.rows = nil then Exit;
Row := aTable.rows.item(aRow, aRow) as IHTMLTableRow;
if Row = nil then Exit;
Result := Row.cells.item(aCol, aCol) as IHTMLElement;
end;
function GetHtmlTable(aDoc: IHTMLDocument2; aIndex: Integer): IHTMLTable;
var
list: IHTMLElementCollection;
begin
Result := nil;
if aDoc = nil then Exit;