F
foxgirl
Unregistered / Unconfirmed
GUEST, unregistred user!
来自:小雨哥, 时间:2003-2-22 4:49:00, ID:1637595
获取网页源代码的最简单办法,就是利用 WinInet 单元中的函数:
uses WinInet;
function GetWebPage(const Url: string):string;
var
Session,
HttpFile:HINTERNET;
szSizeBufferointer;
dwLengthSizeBufferWord;
dwReservedWord;
dwFileSizeWord;
dwBytesReadWord;
ContentsChar;
begin
Session:=InternetOpen('',0,niL,niL,0);
HttpFile:=InternetOpenUrl(Session,PChar(Url),niL,0,0,0);
dwLengthSizeBuffer:=1024;
HttpQueryInfo(HttpFile,5,szSizeBuffer,dwLengthSizeBuffer,dwReserved);
GetMem(Contents,dwFileSize);
InternetReadFile(HttpFile,Contents,dwFileSize,dwBytesRead);
InternetCloseHandle(HttpFile);
InternetCloseHandle(Session);
Result:=StrPas(Contents);
FreeMem(Contents);
end;
使用时,直接把收到的源代码显示出来:
Memo1.Text := GetWebPage('http://www.delphibbs.com/delphibbs/listq.asp');
对于大小不定的网页,就不能正常取出源文件了,该怎么改进?我只有这点分了。
获取网页源代码的最简单办法,就是利用 WinInet 单元中的函数:
uses WinInet;
function GetWebPage(const Url: string):string;
var
Session,
HttpFile:HINTERNET;
szSizeBufferointer;
dwLengthSizeBufferWord;
dwReservedWord;
dwFileSizeWord;
dwBytesReadWord;
ContentsChar;
begin
Session:=InternetOpen('',0,niL,niL,0);
HttpFile:=InternetOpenUrl(Session,PChar(Url),niL,0,0,0);
dwLengthSizeBuffer:=1024;
HttpQueryInfo(HttpFile,5,szSizeBuffer,dwLengthSizeBuffer,dwReserved);
GetMem(Contents,dwFileSize);
InternetReadFile(HttpFile,Contents,dwFileSize,dwBytesRead);
InternetCloseHandle(HttpFile);
InternetCloseHandle(Session);
Result:=StrPas(Contents);
FreeMem(Contents);
end;
使用时,直接把收到的源代码显示出来:
Memo1.Text := GetWebPage('http://www.delphibbs.com/delphibbs/listq.asp');
对于大小不定的网页,就不能正常取出源文件了,该怎么改进?我只有这点分了。