有时候我们查看网页信息,只想查看某些特定区域的信息,那么这时候我们可能会这么做:
//获取源代码
D := FCurWebBrowser.Document as IHTMLDocument2;
e :=d.body as IHTMLElement;
e2 :=e as IHTMLElement2;
cp :=e2.createControlRange as IHTMLControlRange;
d2 :=FCurWebBrowser.Document as IHTMLDocument2;
//获取验证码图片
coll :=(d.all.tags('img') as IHTMLElementCollection);
d2.body.style.visibility :='hidden';
先让所有信息隐藏。
然后遍历所有内容:
for i := 0 to coll.Length - 1 do
begin
//循环取出每个url
elem := (coll.item(i,0) as IHTMLElement);
//当找到元素之后
elem.style.visibility :='visible';
elem.scrollIntoView(True);
end;
这样能显示特定内容,但是又会遇到另一个问题那就是滚动条还在显示。很烦人哦。
为了应对这个问题在页面加载结束之后可以这样操作:
procedure TMainFrm.BaiduWebBrowserDocumentComplete(ASender: TObject; const
pDisp: IDispatch; var URL: OLEVariant);
begin
FCurWebBrowser.OleObject.Document.Body.Scroll := 'no';
FCurWebBrowser.OleObject.Document.Body.style.border := 'none';
FCurWebBrowser.OleObject.Document.Body.Style.margin := '0px';
end;
这样就可以让滚动条消失了。不过消失速度老慢了。还能看到过程。郁闷ing
大家有木有好的方法?