博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(Delphi) Using the Disk Cache 使用磁盘缓存
阅读量:6362 次
发布时间:2019-06-23

本文共 2426 字,大约阅读时间需要 8 分钟。

The Chilkat Spider component has disk caching capabilities. To setup a disk cache, create a new directory anywhere on your local hard drive and set the CacheDir property to the path. For example, you might create "c:/spiderCache/". The UpdateCache property controls whether downloaded pages are saved to the cache. The FetchFromCache property controls whether the cache is first checked for pages. The LastFromCache property tells whether the last URL fetched came from cache or not.

 

uses    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,    Dialogs, StdCtrls,    SPIDERXLib_TLB,    OleCtrls;...procedure TForm1.Button1Click(Sender: TObject);varspider: TSpider;i: Integer;success: Integer;begin//  The Chilkat Spider component/library is free.spider := TSpider.Create(Self);//  Set our cache directory and make sure saving-to-cache and fetching-from-cache//  are both turned on:spider.CacheDir := 'c:/spiderCache/';spider.FetchFromCache := 1;spider.UpdateCache := 1;//  If you run this code twice, you'll find that the 2nd run is extremely fast//  because the pages will be retrieved from cache.//  The spider object crawls a single web site at a time.  As you'll see//  in later examples, you can collect outbound links and use them to//  crawl the web.  For now, we'll simply spider 10 pages of chilkatsoft.comspider.Initialize('www.chilkatsoft.com');//  Add the 1st URL:spider.AddUnspidered('http://www.chilkatsoft.com/');//  Begin crawling the site by calling CrawlNext repeatedly.for i := 0 to 9 do  begin    success := spider.CrawlNext();    if (success = 1) then      begin        //  Show the URL of the page just spidered.        Memo1.Lines.Add(spider.LastUrl);        //  The HTML is available in the LastHtml property      end    else      begin        //  Did we get an error or are there no more URLs to crawl?        if (spider.NumUnspidered = 0) then          begin            ShowMessage('No more URLs to spider');          end        else          begin            ShowMessage(spider.LastErrorText);          end;      end;    //  Sleep 1 second before spidering the next URL.    //  The reason for waiting a short time before the next fetch is to prevent    //  undue stress on the web server.  However, if the last page was retrieved    //  from cache, there is no need to pause.    if (spider.LastFromCache <> 1) then      begin        spider.SleepMs(1000);      end;  end;end;

 

转载地址:http://ffsma.baihongyu.com/

你可能感兴趣的文章
BZOJ 4516: [Sdoi2016]生成魔咒 [后缀自动机]
查看>>
高并发和多线程
查看>>
连接数据库失败 错误提示:尝试读取或写入受保护的内存。这通常指示其他内存已损坏...
查看>>
Linux Bash 脚本:自己定义延迟代码块(裸数据保存方案)
查看>>
verilog 条件编译命令`ifdef、`else、`endif 的应用
查看>>
kafka0.8--0.11各个版本特性预览介绍
查看>>
李洪强iOS经典面试题35-按层遍历二叉树的节点
查看>>
LLDP协议、STP协议 笔记
查看>>
Cygwin-安装和配置ssh服务
查看>>
C#模拟登录后请求查询
查看>>
如何安装和配置RabbitMQ
查看>>
(全然背包)小P寻宝记——好基友一起走
查看>>
uboot下载地址
查看>>
用Go语言写个外挂(上)
查看>>
Java-Servlet--《12-WEB应用中的普通Java程序如何读取资源文件.mp4》 有疑问
查看>>
MS OFFICE WORD 绝招
查看>>
HBase最佳实践-用好你的操作系统
查看>>
二叉排序树
查看>>
JavaSE(一) IO类层次关系和各种IO流的用法总结
查看>>
ios9 之后使用CFNumberGetValue出错
查看>>