求Delphi中提取网页源代码的例子
要求输入一个url,提取这个url的网页。将这个网页的源代码填入一个Memo中就可以了最好能提供一个demo...
要求输入一个url,提取这个url的网页。将这个网页的源代码填入一个Memo中就可以了
最好能提供一个demo 展开
最好能提供一个demo 展开
展开全部
1.用idhttp
const
URL = 'http://www.qq.com';
begin
memo1.lines.text := idhttp1.get(URL);
end;
2.用webbrowser
//只获取到<html>内的源码
const
URL = 'http://www.qq.com';
begin
webbrowser1.Navigate(URL);
while WebBrowser1.Busy do
Application.ProcessMessages;
memo1.lines.Text := WebBrowser1.OleObject.document.documentElement;
end;
//获取全部源码
uses ActiveX;
const
URL = 'http://www.qq.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;
const
URL = 'http://www.qq.com';
begin
memo1.lines.text := idhttp1.get(URL);
end;
2.用webbrowser
//只获取到<html>内的源码
const
URL = 'http://www.qq.com';
begin
webbrowser1.Navigate(URL);
while WebBrowser1.Busy do
Application.ProcessMessages;
memo1.lines.Text := WebBrowser1.OleObject.document.documentElement;
end;
//获取全部源码
uses ActiveX;
const
URL = 'http://www.qq.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;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询