5,388
社区成员
发帖
与我相关
我的任务
分享
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, MSHtml;
type
TForm1 = class(TForm)
wb1: TWebBrowser;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
wb1.Navigate('http://localhost:12880/mtm/abc.htm');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
doc: IHTMLDocument2;
mTable: IHTMLTable;
mRow: IHTMLTableRow;
mCell: IHTMLElement;
mElement: IHTMLElementCollection;
i,j: integer;
begin
doc := wb1.Document as IHTMLDocument2;
mTable := doc.all.item('xxxx',0) as IHTMLTable;
for i:=0 to mTable.rows.length-1 do
begin
mRow := mTable.rows.item(i,0) as IHTMLTableRow;
for j:=0 to mRow.cells.length-1 do
begin
mCell := mRow.cells.item(j,0) as IHTMLElement;
showmessage(mCell.innerHTML);
end;
end;
end;
end.
function RightPos(Substr, S: string): Integer;
begin
Result := Pos(ReverseString(Substr),ReverseString(S));
if Result > 0 then
Result := Length(S) - Result + 1 - Length(Substr) + 1;
end;
(*
#==========================================================
#功能: 返回两个字符串之间的字串
#参数: cStringStr 要截取的字符串
# StartStr 起始的字符串
# EndStr 截止的字符串
#返回: 字符型 截取后的字符串
#==========================================================
*)
function SubStr(cStringStr, StartStr, EndStr: string): string;
var
iStart, iEnd: Longint;
begin
//iStart := pos(StartStr, cStringStr);
iStart := RightPos(StartStr, cStringStr);
//返回指明字串StartStr在字串cStringStr中的iStartPosz之后的位置
if iStart = 0 then
begin
SubStr := ' ';
Exit;
end;
//返回指明字串EndStr在字串cStringStr中的位置
iEnd := Pos(EndStr, cStringStr);
if iEnd = iStart then
begin
SubStr := ' ';
Exit;
end;
//截取字串
if iEnd = 0 then
begin
SubStr := ' ';
exit;
end
else
SubStr := MidBStr(cStringStr, iStart + length(StartStr), iEnd - iStart - Length(StartStr));
end;
(*
#==========================================================
#功能: 返回两个字符串之间的字串
#参数: cStringStr 要截取的字符串
# StartStr 起始的字符串
# EndStr 截止的字符串
#返回: 字符型 截取后的字符串 (截取最右边EndStr,EndStr左边最近的StartStr,中间部分)
#==========================================================
*)
function SubStrExR(cStringStr, StartStr, EndStr: string): string;
var
iStart, iEnd: Longint;
TemStr:string;
begin
//返回指明字串EndStr在字串cStringStr中的位置
iEnd := Pos(EndStr, cStringStr);
TemStr := Copy(cStringStr,1,iEnd);
//iStart := pos(StartStr, cStringStr);
iStart := RightPos(StartStr, TemStr);
//返回指明字串StartStr在字串cStringStr中的iStartPosz之后的位置
if iStart = 0 then
begin
SubStrExR := ' ';
Exit;
end;
if iEnd = iStart then
begin
SubStrExR := ' ';
Exit;
end;
//截取字串
if iEnd = 0 then
begin
SubStrExR := ' ';
exit;
end
else
SubStrExR := MidBStr(cStringStr, iStart + length(StartStr), iEnd - iStart - Length(StartStr));
end;
(*
#==========================================================
#功能: 返回两个字符串之间的字串
#参数: cStringStr 要截取的字符串
# StartStr 起始的字符串
# EndStr 截止的字符串
#返回: 字符型 截取后的字符串 (截取最左边StartStr,StartStr右边最近的EndStr,中间部分)
#==========================================================
*)
function SubStrExL(cStringStr, StartStr, EndStr: string): string;
var
iStart, iEnd: Longint;
TemStr:string;
begin
iStart := pos(StartStr, cStringStr);
TemStr := copy(cStringStr,iStart+length(StartStr)+1,length(cStringStr)-(iStart+length(StartStr)));
//返回指明字串EndStr在字串cStringStr中的位置
iEnd := iStart+length(StartStr) + Pos(EndStr, TemStr);
//返回指明字串StartStr在字串cStringStr中的iStartPosz之后的位置
if iStart = 0 then
begin
SubStrExL := ' ';
Exit;
end;
if iEnd = iStart then
begin
SubStrExL := ' ';
Exit;
end;
//截取字串
if iEnd = 0 then
begin
SubStrExL := ' ';
exit;
end
else
SubStrExL := MidBStr(cStringStr, iStart + length(StartStr), iEnd - iStart - Length(StartStr));
end;