----原文
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Cut, IdCookieManager, IdAntiFreezeBase, IdAntiFreeze,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
StdCtrls, DB, ADODB, Grids, DBGrids, ExtCtrls, ActiveX;
type
TForm1 = class(TForm)
Button3: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
Edit10: TEdit;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
RGet:TThread;
procedure InitList();
procedure GetMMThread(ID,Url,CityID,UrlType,Siteid:TStringList;Sqlstr:string);
public
{ Public declarations }
end;
//线程类
type
TGetMM = class(TThread)
private
//procedure decTcount;
//procedure incTcount;
FID:TStringList;
FUrl:TStringList;
FCityID :TStringList;
FUrltype :TStringList;
FSiteid :TStringList;
FSource :string;
FSqlstr:string;
FADOQuery : TADOQuery;
Fstrm:TStringStream;
FIdGetMM: TIdHTTP;
function Clear(source: string): string;
function Get(source: string;TempList : TStringList): string;
protected
procedure Execute;override;
public
constructor Create(ID,Url,CityID,urltype,Siteid:TStringList;sqlstr:string);
end;
var
Form1: TForm1;
FormTCutString : TCutString;
//tcount :integer;
maxcount : integer;
//flag : boolean;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FormTCutString := TCutString.Create;
FormTCutString.iniFileInit;
FormTCutString.InitUrlList;
InitList();
//Memo1.Lines.Add('初始化成功。。。');
//sleep(40000);
//Button3.Click;
end;
procedure TForm1.InitList;
var
sqlstr :string;
i : integer;
InitQuery: TADOQuery;
begin
try
InitQuery := TADOQuery.Create(nil);
InitQuery.ConnectionString := ConnStr;
with InitQuerydo
begin
i :=0;
sqlstr :='update urlinfo set online=2 where id in (select top 5 id from urlinfo where online=0)';
InitQuery.SQL.Clear;
InitQuery.SQL.Text := sqlstr;
InitQuery.ExecSQL;
sleep(1000);
sqlstr := 'select top 5 id,url,urltype,cityid,siteid from urlinfo where online=2';
//where urltype='+Urltype+' and cityid ='+CityID+' order by id';
InitQuery.SQL.Clear;
InitQuery.SQL.Text := sqlstr;
try
InitQuery.Open;
while not InitQuery.Eofdo
begin
IDList.Insert(i,InitQuery.FieldByName('id').AsString);
UrlList.Insert(i,InitQuery.FieldByName('url').AsString);
UrltypeList.Insert(i,InitQuery.FieldByName('urltype').AsString);
CityIDList.Insert(i,InitQuery.FieldByName('CityID').AsString);
SiteidList.Insert(i,InitQuery.FieldByName('siteid').AsString);
i := i+1;
InitQuery.Next;
end;
maxcount := i;
except on E:Exceptiondo
showmessage('初始化失败!');
end;
end;
finally
InitQuery.Free;
end;
end;
{ TGetMM }
function TGetMM.Clear(source: string): string;
begin
--此处完成分析整理HTML
end;
constructor TGetMM.Create(ID,Url,CityID,UrlType,Siteid:TStringList;Sqlstr: string);
begin
FID:=ID;
FUrl:=Url;
FCityID :=CityID;
FUrlType :=UrlType;
FSiteid :=Siteid;
Fsqlstr :=Sqlstr;
FreeOnTerminate := true;
Fstrm:=TStringStream.Create('');
sleep(2000);
FIdGetMM:= TIdHTTP.Create(nil);
sleep(2000);
FADOQuery:= TADOQuery.Create(nil);
FADOQuery.ConnectionString :=ConnStr;
inherited Create(False);
end;
procedure TGetMM.Execute;
var
i : integer;
begin
CoInitialize(nil);
for i:=0 to FUrl.Count-1do
begin
try
FIdGetMM.Get(FUrl.Strings,Fstrm);
sleep(3000);
Fsource := Fstrm.DataString;
Fsource :=Clear(Fsource);
try
Fsqlstr :='insert into rentinfo(url,district,area,provider,telephone,floor,size,room,buildyear,towards,price) values(';
Fsqlstr :=Fsqlstr +''''+FUrl.Strings+''''+','+''''+Get(Fsource,DistrictList)+''''+','+''''+Get(Fsource,AreaList)+''''+','+''''+Get(Fsource,ProviderList)+''''+','+''''+Get(Fsource,TelephoneList)+''''+','+''''+Get(Fsource,FloorList)+''''+','+''''+Get(Fsource,SizeList)+''''+','+''''+Get(Fsource,RoomList)+''''+','+''''+Get(Fsource,YearList)+''''+','+''''+Get(Fsource,TowardsList)+''''+','+''''+Get(Fsource,PriceList)+''''+')';
FADOQuery.SQL.Clear;
FADOQuery.SQL.Text := Fsqlstr;
FADOQuery.ExecSQL;
sleep(500);
Fsqlstr :='update urlinfo set online=1 where id='+FID.Strings;
FADOQuery.SQL.Clear;
FADOQuery.SQL.Text := Fsqlstr;
FADOQuery.ExecSQL;
sleep(500);
except
Fsqlstr :='update urlinfo set online=3 where id='+FID.Strings;
FADOQuery.SQL.Clear;
FADOQuery.SQL.Text := Fsqlstr;
FADOQuery.ExecSQL;
end;
finally
//FADOQuery.Free;
//FIdGetMM.Free;
end;
end;
CoUninitialize;
end;
procedure TForm1.GetMMThread(ID,Url,CityID,UrlType,Siteid:TStringList;Sqlstr: string);
begin
RGet :=TGetMM.Create(ID,Url,CityID,UrlType,Siteid,Sqlstr);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
sleep(1000);
GetMMThread(IDList,UrlList,CityIDList,UrlTypeList,SiteidList,'');
end;
function TGetMM.Get(source: string;
TempList: TStringList): string;
begin
--提取信息
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
InitList();
if maxcount>0 then
Button3.Click;
end;
{
initialization
CoInitialize(nil);
finalization
CoUninitialize;}
end.