delphi快速獲取網(wǎng)頁源碼方法 1.用idhttp const URL = 'http://www.baidu.com'; begin memo1.lines.text := idhttp1.get(URL); end; 2.用webbrowser //只獲取到<html>內(nèi)的源碼 const URL = 'http://www.'; begin webbrowser1.Navigate(URL); while WebBrowser1.Busy do Application.ProcessMessages; memo1.lines.Text := WebBrowser1.OleObject.document.documentElement; end; //獲取全部源碼 uses ActiveX; const URL = 'http://www.baidu.com'; var ms: TMemoryStream; begin WebBrowser1.Navigate(URL); while WebBrowser1.Busy do Application.ProcessMessages; ms := TMemoryStream.Create; try (WebBrowser1.Document as IPersistStreamInit).Save(TStreamAdapter.Create(ms), True); ms.Position := 0; Memo1.Lines.LoadFromStream(ms); finally FreeAndNil(ms); end; end; |
|
來自: 昵稱25617555 > 《源碼》