Delphi TWebBrowser[8] 访问网页中的表格

Delphi TWebBrowser[8] 访问网页中的表格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use MSHTML;
 
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;
  if aDoc.all = nil then Exit;
  list := aDoc.all.tags('table') as IHTMLElementCollection;
  if list = nil then Exit;
  Result := list.item(aIndex,aIndex) as IHTMLTable;
end;
 
function GetWebBrowserHtmlTableCellText(const AWebBrowser: TWebBrowser;
  const TableIndex, RowIndex, ColIndex: Integer;
  var ResValue: string): Boolean;
var
  Docintf: IHTMLDocument2;
  tblintf: IHTMLTable;
  node: IHTMLElement;
begin
  ResValue := '';
  docintf := AWebBrowser.Document as IHTMLDocument2;
  tblintf := GetHtmlTable(docintf, TableIndex);
  node := GetHtmlTableCell(tblintf, RowIndex, ColIndex);
  Result := node <> nil;
  if Result then
    ResValue := Trim(node.innerText);
end;
 
function GetHtmlTableRowHtml(aTable: IHTMLTable; aRow: 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 as IHTMLElement;
end;
 
function GetWebBrowserHtmlTableCellHtml(const AWebBrowser: TWebBrowser;
  const TableIndex, RowIndex, ColIndex: Integer;
  var ResValue: string): Boolean;
var
  Docintf: IHTMLDocument2;
  tblintf: IHTMLTable;
  node: IHTMLElement;
begin
  ResValue := '';
  docintf := AWebBrowser.Document as IHTMLDocument2;
  tblintf := GetHtmlTable(docintf, TableIndex);
  node := GetHtmlTableCell(tblintf, RowIndex, ColIndex);
  Result := node <> nil;
  if Result then
    ResValue := Trim(node.innerHTML);
end;
 
function GeHtmlTableHtml(aTable: IHTMLTable; aRow: 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 as IHTMLElement;
end;
 
function GetWebBrowserHtmlTableHtml(const AWebBrowser: TWebBrowser;
  const TableIndex, RowIndex: Integer;
  var ResValue: string): Boolean;
var
  Docintf: IHTMLDocument2;
  tblintf: IHTMLTable;
  node: IHTMLElement;
begin
  ResValue := '';
  docintf := AWebBrowser.Document as IHTMLDocument2;
  tblintf := GetHtmlTable(docintf, TableIndex);
  node := GeHtmlTableHtml(tblintf, RowIndex);
  Result := node <> nil;
  if Result then
    ResValue := node.innerHtml;
end;

  

创建时间:2020.11.23  更新时间:

posted on   滔Roy  阅读(287)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报

导航

点击右上角即可分享
微信分享提示