得到ie的源码中的问题(300分)

G

g622

Unregistered / Unconfirmed
GUEST, unregistred user!
ShellWindow := CoShellWindows.Create;
nCount := ShellWindow.Count;
for i := 0 to nCount - 1 do
begin
vi := i;
spDisp := ShellWindow.Item(vi);
if spDisp = nil then continue;
spDisp.QueryInterface( iWebBrowser2, IE1 );
if IE1 <> nil then
begin
IE1.Document.QueryInterface(IHTMLDocument2,iDoc1);
if iDoc1 <> nil then
begin
ielc:=idoc1.Get_all;
for j:=0 to ielc.length-1 do
begin
IhtmlEle := ielc.item(j,0) as IhtmlElement;
if (assigned(idoc1)) then
tmps:=tmps+uppercase(IhtmlEle.innerHTML);

这个是用来取得所有ie的html源码的,奇怪的是得到的html中有很多重复的。
比如sina的首页这样得到的居然有1.6M之多,实际只有100k.有谁知道是位什么吗?
 
我倒是有办法得到ie浏览的源码,方法和你不同。

如果需要请Email:jollier@371.net
 
IHtmlDocument2(IE1.Document).Body.OuterHtml
简单而有效。
 
zw84611:
这样得到的是一部分吧,我在sina上试验的结果。
 
Document.body.outerhtml
得到的几乎是全部的
至少够用了
 
可是得到的是很少的部分 你也可以试一下
 
用代理,什么数据都送你这里过
本机代理
 
小黄鱼:不打算用这种方法
 
[:)]To g622[:)]
用[blue]WebBrowser1.OleObject.document.all.tags('HTML').item(0).outerHTML[/blue]
[red]几乎[/red]可以得到所有的内容!

你得到HTML中有很多重复的地方,关键在于你的最后一条语句:
[blue]tmps:=tmps+uppercase(IhtmlEle.innerHTML);[/blue]
innerHTML属性是很多HTML标签所具有的,
上层标签中的innerHTML包含了子标签中的innerHTML。
举个例子,相信你很快就会明白:
代码:
[red]<BODY>
     <p id=test>This a abbreviated HTML test</p>
 </BODY>[/red]
OleObject.document.all.tags('BODY').item(0).innerHTML的内容为:
[blue]<p id=test>This a abbreviated HTML test</p>[/blue]
OleObject.document.all.tags('P').item(0).innerHTML的内容为:
[blue]This a abbreviated HTML test[/blue]
很明显,它们存在冗余的内容。
 
多人接受答案了。
 
顶部