Delphi 获取网页源代码的最简单办法


本文整理自网络,侵删。

 
获取网页源代码的最简单办法,就是利用 WinInet 单元中的函数:
uses WinInet;
function GetWebPage(const Url: string):string;
var
  Session,
  HttpFile:HINTERNET;
  szSizeBuffer:Pointer;
  dwLengthSizeBuffer:DWord;
  dwReserved:DWord;
  dwFileSize:DWord;
  dwBytesRead:DWord;
  Contents:PChar;
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.delphitop.com/');

相关阅读 >>

fmsoft_unigui个文件说明

Delphi线程池

Delphi 一个拼图工具的制作思路

Delphi 编写activex控件(ocx控件)的知识和样例

Delphi unigui 获取files路径

Delphi xe5实现android 安卓 左侧或者右侧菜单功能

Delphi memo1文本搜索并高亮

Delphi文件分割合并

Delphi 字符串加密与解密函数

Delphi监控指定进程防止被关闭

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...