procedure TForm1.Button1Click(Sender: TObject);
var
sUrl:string;
ihMyIdHttp:TIdHTTP;
ihMyIdHttp1:TIdHTTP;
iFrom:Integer;
iTo:Integer;
i:Integer;
sInfo:string;
sName:string;
list:TStringList;
o:Integer;
p:Integer;
list1:TStringList;
list2:TStringList;
s公司名称:string;
s会员级别:string;
s联系人:string;
sQQ:string;
s电话:string;
s移动电话:string;
s传真:string;
s网址:string;
sSubInfo:string;
begin
ListView1.Items.Clear;
if (Edit1.Text='') or (Edit2.Text='') then
begin
ShowMessage('请输入搜索范围');
Exit;
end;
iFrom:=StrToInt(Edit1.Text);
iTo:=StrToInt(Edit2.Text);
ListView1.ViewStyle:=vsReport;
ihMyIdHttp:=TIdHTTP.Create(nil);
for i := iFrom to iTo do
begin
sUrl:='http://www.sg560.com/company/cate_area-0/date_key_/p'+i.ToString+'.html';
ShowMessage(sUrl);
sInfo:=ihMyIdHttp.Get(sUrl);
sInfo:=CopyStr(sInfo,'<div class="result-list-content">','<div class="clearfix">');
SplitString(sInfo,'<a class="g-imgTxt-tl" href="',list);
ihMyIdHttp1:=TIdHTTP.Create(nil);
for o := 0 to list.Count-1 do
begin
p:=o;
p:=p*2+1;
if p=21 then
Exit;
SplitString(list[p],'" title="',list1);
s网址:='http://www.sg560.com'+list1[0];
SplitString(list1[1],'"',list2);
s公司名称:=list2[0];
sSubInfo:=ihMyIdHttp1.Get(s网址);
sSubInfo:=CopyStr(sSubInfo,'<div class="header">','<div class="mright">');
s会员级别:=CopyStr(sSubInfo,'<div class="name2">','</div>');
s会员级别:=s会员级别+':第'+CopyStr(sSubInfo,'<span class="num">','</span>')+'年';
s联系人:=CopyStr(sSubInfo,'<p class="mlp2">','<a');
s联系人:=CopyStr(s联系人,'<span>','</span>');
sQQ:=CopyStr(sSubInfo,'&uin=','&site');
s电话:=CopyStr(sSubInfo,'电 话:','<br />');
s移动电话:=CopyStr(sSubInfo,'移动电话:','<br />');
s传真:=CopyStr(sSubInfo,'传 真:','</p>');
if s会员级别<>'免费会员' then
begin
with ListView1.Items.Add do
begin
//Caption:=IntToStr('1');
SubItems.Add('22');
SubItems.Add(s公司名称);
SubItems.Add(s会员级别);
SubItems.Add(s联系人);
SubItems.Add(sQQ);
SubItems.Add(s电话);
SubItems.Add(s移动电话);
SubItems.Add(s传真);
SubItems.Add(s网址);
try
listview1.Items[listview1.Items.Count-1].MakeVisible(true);
except
on E:Exception do
ShowMessage('异常:'+E.Message);
end;
end;
end;
end;
ihMyIdHttp.Free;
ihMyIdHttp1.Free;
end;
end;