您的位置:首页 > 其它

WebBrowser 获取网页内容

2014-01-15 16:09 267 查看
1.wb.OleObject.document.documentelement.innerhtml
2.utf8toansi(getHtml(wb))
utf8toansi函数
function getHtml(const
WebBrowser:TWebBrowser):string;

const

  BufSize = $10000;

var

  Size: Int64;

  Stream: IStream;

  hHTMLText: HGLOBAL;

  psi: IPersistStreamInit;

begin

  if not Assigned(WebBrowser.Document) then

    Exit;

 
OleCheck(WebBrowser.Document.QueryInterface(IPersistStreamInit,pSi));

  try

    hHTMLText :=
GlobalAlloc(GPTR,BufSize);

   
OleCheck(CreateStreamOnHGlobal(hHTMLText,True,Stream));

    try

     
OleCheck(Psi.Save(Stream,False));

     
Size := StrLen(PChar(hHTMLText));

     
SetLength(Result,Size);

     
CopyMemory(PChar(Result),Pointer(hHTMLText),Size);

   
finally

     
Stream := nil;

    end;

  finally

    pSi :=
nil;

  end;

end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: