// ce scripte a pour but de vous montrer comment aspirer les résultats des pages jaunes belges

AUTORUN;
var s: String;
var tab: Tstringlist;tab:=Tstringlist.create;
var i: integer;
var ajoutes:integer;

// ici la définitions des variables
var description : string;
var email : string;                               
var name : string;        
var website : string;
var phone : string;
var adresse,fax : string;

createTable('description','email','name','website','phone','fax');
SetUniqueColumn('name');



navigate('http://www.pagesdor.be');
showmessage('Choisissez votre catégorie, votre provence et naviguez jusqu''aux premiers résultats');

repeat;
    sleep(10);
    s:=getBrowserUrl(1);
until pos('result.asp',s)>0;

showDatabase;

repeat;
ajoutes:=recordCount;
for i:=52 downto 1 do begin;
    s:='TD(0)/TR(3)/TBODY(0)/TABLE(0)/TD(0)/TR('+inttostr(i)+')/TBODY(0)/TABLE(0)/TD(1)/TR(0)/TBODY(0)/TABLE(0)/TD(0)/TR(0)/TBODY(0)/TABLE(0)/TD(0)/TR(1)/TBODY(0)/TABLE(0)/BODY(0)/HTML(0)/';
    tab.text:=getText(s,1);
    name:='';
    adresse:='';
    description:='';
    email:='';
    website:='';

    if tab.count>0 then name:=tab[0];
    if (tab.count)>3 then adresse:=tab[1]+tab[2]+tab[3];
    if (tab.count)>1 then  description:=tab[1];


    s:='TD(0)/TR(1)/TBODY(0)/TABLE(0)/TD(0)/TR('+inttostr(i)+')/TBODY(0)/TABLE(0)/TD(1)/TR(0)/TBODY(0)/TABLE(0)/TD(0)/TR(0)/TBODY(0)/TABLE(0)/TD(0)/TR(1)/TBODY(0)/TABLE(0)/BODY(0)/HTML(0)/';
    tab.text:=getHTML(s,1);
    s:=tab.text;
    email:=extractEmails(tab.text);
    website:=extractUrlsfromString(tab.text);
    i:=1;website:=parsetag(website,'?url=','',i);
    if trim(name)<>'' then InsertData(description,email,name,website,phone,fax);
end;
// on clique sur le lien suivant


clickForm('A(1)/SPAN(0)/TD(0)/TR(0)/TBODY(0)/TABLE(0)/TD(0)/TR(1)/TBODY(0)/TABLE(0)/TD(1)/TR(0)/TBODY(0)/TABLE(0)/TD(0)/TR(0)/TBODY(0)/TABLE(0)/TD(0)/TR(1)/TBODY(0)/TABLE(0)/BODY(0)/HTML(0)/',1);


ajoutes:=recordcount-ajoutes;
until (ajoutes=0);