Delphi获取网页源代码各种不同方法
获取网页源代码有几种方式,
1.不打开网页获取网页源码
var
IdHTTP1: TIdHTTP;
begin
IdHTTP1:=TIdHTTP.Create;
memo1.Text:= idhttp1.Get('http://www.mp4ku.com');
IDhttp1.Free;
end;
2.打开网页获取
1)var
ms: TMemoryStream;
URL: string;
begin
URL := edit1.Text;
EmbeddedWB1.Navigate(URL);
while EmbeddedWB1.Busy do
Application.ProcessMessages;
ms := TMemoryStream.Create;
try
(EmbeddedWB1.Document as IPersistStreamInit).Save(TStreamAdapter.Create(ms), True);
ms.Position := 0;
Memo1.Lines.LoadFromStream(ms);
finally
FreeAndNil(ms);
end;
end;
2)这个实在是太简单啦:
memo1.Lines.Text:=IHtmlDocument2(EmbeddedWB1.document).body.outerHTML;
哈哈,一句话就搞定。但这个前提是要在EmbeddedWB里打开了你所要的网页,如果没打开,就
EmbeddedWB1.Navigate('');但要确定打开完全了,判断网页是否完全打开可以加上:
while EmbeddedWB1.Busy do
Application.ProcessMessages;然后再加上上面那个outerHTML就好啦!
但是发现老在idhttp1.get处老报错:unknown protocol;折腾了半天,网上搜也搜不出答案,终于发现是因为没有加“http://”的缘故,讨厌,现在终于解决了,发上来让各位知悉。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30253994/viewspace-1663832/
,如需转载,请注明出处,否则将追究法律责任。