Delphi中提取网页源代码


1.用idhttp
const
URL = 'http://www.3464.com';
begin
memo1.lines.text := idhttp1.get(URL);
end;
2.用webbrowser
//只获取到内的源码
const
URL = 'http://www.4936.cn';
begin
webbrowser1.Navigate(URL);
while WebBrowser1.Busy do
 Application.ProcessMessages;
memo1.lines.Text := WebBrowser1.OleObject.document.documentElement;
end;
//获取全部源码
uses ActiveX;
const
URL = 'http://www.521.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;

联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678