我需要提取用frontpage做的一个简单网页的源码,和网页里的所有元素及其它们的属性.
我查了一些资料,在delphi中用mshtml单元和webbrower控件,有些元素属性提取不出来!!!
谁用过mshtml单元和webbrower控件?帮忙给我提个建议!
我写的demo:
unit UnitHtml;interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, ExtCtrls,MSHTML;type
HtmlImg = record
imgsrc : string;
imgborder: string;
imgwidth: string;
imgheight: string;
imgalign: string;
end;function getImg(WebBrowser: TWebBrowser): HtmlImg; //获取图片implementationfunction getImg(WebBrowser: TWebBrowser): HtmlImg; //背景图片
var
doc:IHTMLDocument2;
all:IHTMLElementCollection;
len,i,flag:integer;
item:IHTMLElement;
vAttri:Variant;
//img: HtmlImg;
begin
Result.imgsrc:= '';
Result.imgborder:= '';
Result.imgwidth:= '';
result.imgheight:= '';
result.imgalign:= '';
if Assigned(WebBrowser) then
begin
//获得Webbrowser对象中的文档对象
doc:=WebBrowser.Document as IHTMLDocument2;
//获得文档中所有的HTML元素集合
all:=doc.Get_all;
len:=all.Get_length;
//访问HTML元素集合中的每一个元素
for i:=0 to len-1 do
begin
item:=all.item(i,varempty) as IHTMLElement;
//如果该元素是一个图片
if item.Get_tagName = UpperCase('img') then
begin
flag:=0;
vAttri:= item.getAttribute('src',flag); //获得图片源属性
if vAttri <> null then
Result.imgsrc:= vAttri;
vAttri:= item.getAttribute('border',flag);//获取图片边框
if vAttri <> null then
Result.imgborder:= vAttri;
vAttri:= item.getAttribute('width',flag);//获取图片宽度
if vAttri <> null then
result.imgwidth:= vAttri;
vAttri:= item.getAttribute('height',flag);//获取图片高度
if vAttri <> null then
result.imgheight:= vAttri;
end;
end;
end;
end;上面那个函数我只取出来imgsrc,imgborder,但是imgwidth和imgheight取不出来!
兄弟们帮帮忙,分不够再加!
我查了一些资料,在delphi中用mshtml单元和webbrower控件,有些元素属性提取不出来!!!
谁用过mshtml单元和webbrower控件?帮忙给我提个建议!
我写的demo:
unit UnitHtml;interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, ExtCtrls,MSHTML;type
HtmlImg = record
imgsrc : string;
imgborder: string;
imgwidth: string;
imgheight: string;
imgalign: string;
end;function getImg(WebBrowser: TWebBrowser): HtmlImg; //获取图片implementationfunction getImg(WebBrowser: TWebBrowser): HtmlImg; //背景图片
var
doc:IHTMLDocument2;
all:IHTMLElementCollection;
len,i,flag:integer;
item:IHTMLElement;
vAttri:Variant;
//img: HtmlImg;
begin
Result.imgsrc:= '';
Result.imgborder:= '';
Result.imgwidth:= '';
result.imgheight:= '';
result.imgalign:= '';
if Assigned(WebBrowser) then
begin
//获得Webbrowser对象中的文档对象
doc:=WebBrowser.Document as IHTMLDocument2;
//获得文档中所有的HTML元素集合
all:=doc.Get_all;
len:=all.Get_length;
//访问HTML元素集合中的每一个元素
for i:=0 to len-1 do
begin
item:=all.item(i,varempty) as IHTMLElement;
//如果该元素是一个图片
if item.Get_tagName = UpperCase('img') then
begin
flag:=0;
vAttri:= item.getAttribute('src',flag); //获得图片源属性
if vAttri <> null then
Result.imgsrc:= vAttri;
vAttri:= item.getAttribute('border',flag);//获取图片边框
if vAttri <> null then
Result.imgborder:= vAttri;
vAttri:= item.getAttribute('width',flag);//获取图片宽度
if vAttri <> null then
result.imgwidth:= vAttri;
vAttri:= item.getAttribute('height',flag);//获取图片高度
if vAttri <> null then
result.imgheight:= vAttri;
end;
end;
end;
end;上面那个函数我只取出来imgsrc,imgborder,但是imgwidth和imgheight取不出来!
兄弟们帮帮忙,分不够再加!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货