Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
GetBaseDomain
See more Spider Examples
The GetBaseDomain method is a utility function that converts a domain into a "domain base", which is useful for grouping URLs. For example: abc.chilkatsoft.com, xyz.chilkatsoft.com, and blog.chilkatsoft.com all have the same base domain: chilkatsoft.com. Things get more complicated when considering country domains (.au, .uk, .se, .cn, etc.) and government, state, and .us domains. Also, domains such as blogspot, wordpress, etc, are treated specially so that "xyz.blogspot.com" has a base domain of "xyz.blogspot.com". Note: If you find other domains that should be treated similarly to blogspot.com, send a request to support@chilkatsoft.com.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Spider;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
spider: TSpider;
begin
spider := TSpider.Create;
WriteLn(spider.GetBaseDomain('www.chilkatsoft.com'));
WriteLn(spider.GetBaseDomain('blog.chilkatsoft.com'));
WriteLn(spider.GetBaseDomain('www.news.com.au'));
WriteLn(spider.GetBaseDomain('blogs.bbc.co.uk'));
WriteLn(spider.GetBaseDomain('xyz.blogspot.com'));
WriteLn(spider.GetBaseDomain('www.heaids.org.za'));
WriteLn(spider.GetBaseDomain('www.hec.gov.pk'));
WriteLn(spider.GetBaseDomain('www.e-mrs.org'));
WriteLn(spider.GetBaseDomain('cra.curtin.edu.au'));
// Prints:
// chilkatsoft.com
// chilkatsoft.com
// news.com.au
// bbc.co.uk
// xyz.blogspot.com
// heaids.org.za
// hec.gov.pk
// e-mrs.org
// curtin.edu.au
spider.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.