?? unitsearch.~pas
字號:
unit UnitSearch;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables, IdHTTP, ADODB;
//定義標識符記錄結(jié)構(gòu)體,用作參數(shù)傳到Search函數(shù)
type
TIdentifier = Record
//要進行搜索的地址
URL:string;
//搜索結(jié)果總數(shù)的前面的字符串和后面的字符串
TotalPrev,TotalRear:string;
//每一頁顯示的項目數(shù)
ItemAmountPerPage:Integer;
//翻頁參數(shù),函數(shù)式為 i*PageIndex+PageBegin
PageIndex,PageBegin:Integer;
//關(guān)鍵字和翻頁的參數(shù)名
KeywordID,PageID:string;
//在代碼中是否存在數(shù)字序號
HasNO:Boolean;
//一個記錄的開始標識符和結(jié)束標識符
ItemPrev,ItemRear:string;
//鏈接的開始標識符和結(jié)束標識符
LinkPrev,LinkRear:string;
//標題的開始標識符和結(jié)束標識符
HeadPrev,HeadRear:string;
//內(nèi)容的開始標識符和結(jié)束標識符
ContentPrev,ContentRear:string;
//搜索結(jié)果的來源
Source:string;
end;
type
//定義百度搜索類
TBaiduSearch = class(TThread)
BaiduID:TIdentifier;
procedure ThreadDone(Sender: TObject);
protected
procedure Execute; override;
public
constructor Create;
end;
//定義Google搜索類
TGoogleSearch = class(TThread)
GoogleID:TIdentifier;
procedure ThreadDone(Sender: TObject);
protected
procedure Execute; override;
public
constructor Create;
end;
//定義21cn搜索類
T_21cnSearch = class(TThread)
_21cnID:TIdentifier;
procedure ThreadDone(Sender: TObject);
protected
procedure Execute; override;
public
constructor Create;
end;
//定義新浪搜索類
TSinaSearch = class(TThread)
SinaID:TIdentifier;
procedure ThreadDone(Sender: TObject);
protected
procedure Execute; override;
public
constructor Create;
end;
//定義搜狐搜索類
TSohuSearch = class(TThread)
SohuID:TIdentifier;
procedure ThreadDone(Sender: TObject);
protected
procedure Execute; override;
public
constructor Create;
end;
//定義雅虎搜索類
TYahooSearch = class(TThread)
YahooID:TIdentifier;
procedure ThreadDone(Sender: TObject);
protected
procedure Execute; override;
public
constructor Create;
end;
//定義IdHTTP
TMyIdHTTP = class(TIdHTTP)
//定義連接事件
procedure Connected(Sender: TObject);
protected
//是否獲取到頁面
GotWebPage:Boolean;
end;
procedure Decrease;
procedure ShowDone(Engine: string);
procedure Search(Identifier: TIdentifier);
implementation
uses MainFrm, CustomSearchFrm;
//構(gòu)造每個搜索類線程
constructor TBaiduSearch.Create;
begin
FreeOnTerminate:=True;
OnTerminate:=ThreadDone;
inherited Create(False);
end;
constructor TGoogleSearch.Create;
begin
FreeOnTerminate:=True;
OnTerminate:=ThreadDone;
inherited Create(False);
end;
constructor T_21cnSearch.Create;
begin
FreeOnTerminate:=True;
OnTerminate:=ThreadDone;
inherited Create(False);
end;
constructor TSinaSearch.Create;
begin
FreeOnTerminate:=True;
OnTerminate:=ThreadDone;
inherited Create(False);
end;
constructor TSohuSearch.Create;
begin
FreeOnTerminate:=True;
OnTerminate:=ThreadDone;
inherited Create(False);
end;
constructor TYahooSearch.Create;
begin
FreeOnTerminate:=True;
OnTerminate:=ThreadDone;
inherited Create(False);
end;
//定義每個線程的執(zhí)行操作
procedure TBaiduSearch.Execute;
begin
//設(shè)定標識符記錄結(jié)構(gòu)體
BaiduID.URL:='http://www.baidu.com/baidu?';
BaiduID.TotalPrev:='找到相關(guān)網(wǎng)頁約';
BaiduID.TotalRear:='篇';
BaiduID.KeywordID:='word';
BaiduID.PageID:='pn';
BaiduID.ItemAmountPerPage:=10;
BaiduID.PageIndex:=10;
BaiduID.PageBegin:=0;
BaiduID.HasNO:=False;
BaiduID.ItemPrev:='<p class=p2>';
BaiduID.ItemRear:='</a>';
BaiduID.LinkPrev:='href=';
BaiduID.LinkRear:='target="_blank">';
BaiduID.HeadPrev:='target="_blank">';
BaiduID.HeadRear:='</a>';
BaiduID.ContentPrev:='<font size=-1>';
BaiduID.ContentRear:='<font color=#008000>';
BaiduID.Source:='百度';
//調(diào)用搜索過程進行搜索
Search(BaiduID);
end;
procedure TGoogleSearch.Execute;
begin
//
end;
procedure T_21cnSearch.Execute;
begin
//設(shè)定標識符記錄結(jié)構(gòu)體
_21cnID.URL:='http://cha.21cn.com/result_all.php?tn=21cn&';
_21cnID.TotalPrev:='21cn搜索為您找到 <font color="#FF0000">';
_21cnID.TotalRear:='</font>'; //'</font> 個有關(guān)'; // #$d+#$A+
_21cnID.KeywordID:='word';
_21cnID.PageID:='pn';
_21cnID.ItemAmountPerPage:=10;
_21cnID.PageIndex:=10;
_21cnID.PageBegin:=1;
_21cnID.HasNO:=True;
_21cnID.ItemPrev:='.</td>';
_21cnID.ItemRear:='</table>';
_21cnID.LinkPrev:='href="';
_21cnID.LinkRear:='" target=_blank>';
_21cnID.HeadPrev:='target=_blank>';
_21cnID.HeadRear:='</a>';
_21cnID.ContentPrev:='<font size="-1">'; //'<font style="font-size:11pt">'+#$D+#$A;
_21cnID.ContentRear:='</font><br>'; //#$D+#$A;
_21cnID.Source:='21cn';
//調(diào)用搜索過程進行第一次搜索
Search(_21cnID);
//設(shè)定標識符記錄結(jié)構(gòu)體
_21cnID.URL:='http://dir.21cn.com/query.php?tn=21cndir&';
_21cnID.TotalPrev:='普通站點<font color="gray">(';
_21cnID.TotalRear:=')</font>';
_21cnID.KeywordID:='query';
_21cnID.PageID:='cur_page';
_21cnID.ItemAmountPerPage:=20;
_21cnID.PageIndex:=1;
_21cnID.PageBegin:=1;
_21cnID.HasNO:=True;
_21cnID.ItemPrev:='</font>] ';
_21cnID.ItemRear:='</td>';
_21cnID.LinkPrev:='href="';
_21cnID.LinkRear:='">';
_21cnID.HeadPrev:='<font class="p1">';
_21cnID.HeadRear:=#$A;
_21cnID.ContentPrev:='<td colspan="2" class="p1">';
_21cnID.ContentRear:='<br>';
_21cnID.Source:='21cn';
//調(diào)用搜索過程進行第二次搜索
Search(_21cnID);
end;
procedure TSinaSearch.Execute;
begin
//設(shè)定標識符記錄結(jié)構(gòu)體
SinaID.URL:='http://search.sina.com.cn/cgi-bin/search/search.cgi?';
SinaID.TotalPrev:='相關(guān)網(wǎng)站 ';
SinaID.TotalRear:=' 個</TD>';
SinaID.KeywordID:='_searchkey';
SinaID.PageID:='_begin';
SinaID.ItemAmountPerPage:=30;
SinaID.PageIndex:=30;
SinaID.PageBegin:=1;
SinaID.HasNO:=True;
SinaID.ItemPrev:='. </TD>'; //'. ';
SinaID.ItemRear:='</TABLE>';
SinaID.LinkPrev:='href="';
SinaID.LinkRear:='" target=_blank >'; //' target=_blank';
SinaID.HeadPrev:='" target=_blank >'; //'class=f15>';
SinaID.HeadRear:='</a>';
SinaID.ContentPrev:='<FONT color=#333333 class=f15>'; //'<font color=#333333>';
SinaID.ContentRear:='</FONT>';
SinaID.Source:='新浪';
//調(diào)用搜索過程進行第一次搜索
Search(SinaID);
//設(shè)定標識符記錄結(jié)構(gòu)體
SinaID.URL:='http://webpage.sina.com.cn/cgi-bin/search/webpage.cgi?';
SinaID.TotalPrev:='共找到 <b>';
SinaID.TotalRear:='</b>';
SinaID.KeywordID:='word';
SinaID.PageID:='start';
SinaID.ItemAmountPerPage:=20;
SinaID.PageIndex:=20;
SinaID.PageBegin:=0;
SinaID.HasNO:=True;
SinaID.ItemPrev:='. ';
SinaID.ItemRear:='</table>';
SinaID.LinkPrev:='href="';
SinaID.LinkRear:='" target="_blank"';
SinaID.HeadPrev:='<font class=f15>';
SinaID.HeadRear:='</font>';
SinaID.ContentPrev:='</a>';
SinaID.ContentRear:='<font color="#800040">';
SinaID.Source:='新浪';
//調(diào)用搜索過程進行第二次搜索
Search(SinaID);
end;
procedure TSohuSearch.Execute;
begin
//設(shè)定標識符記錄結(jié)構(gòu)體
SohuID.URL:='http://site.search.sohu.com/website.jsp?';
SohuID.TotalPrev:='共找到 '; //'網(wǎng)站搜索中共有 ';
SohuID.TotalRear:=' 結(jié)果';
SohuID.KeywordID:='key_word';
SohuID.PageID:='begin';
SohuID.ItemAmountPerPage:=30;
SohuID.PageIndex:=30;
SohuID.PageBegin:=0;
SohuID.HasNO:=False;
SohuID.ItemPrev:='<li>';
SohuID.ItemRear:='</li>';
SohuID.LinkPrev:='href="';
SohuID.LinkRear:='" onmousedown';
SohuID.HeadPrev:='target='+''''+'_blank'+''''+'>';
SohuID.HeadRear:='</a><br>';
SohuID.ContentPrev:='</a><br>';
SohuID.ContentRear:='</font>';
SohuID.Source:='搜狐';
//調(diào)用搜索過程進行第一次搜索
Search(SohuID);
//設(shè)定標識符記錄結(jié)構(gòu)體
SohuID.URL:='http://page.search.sohu.com/cgi-bin/pagesearch.cgi?';
SohuID.TotalPrev:='網(wǎng)頁搜索中共有 ';
SohuID.TotalRear:=' 個查詢結(jié)果';
SohuID.KeywordID:='word';
SohuID.PageID:='bg';
SohuID.ItemAmountPerPage:=10;
SohuID.PageIndex:=1;
SohuID.PageBegin:=1;
SohuID.HasNO:=False;
SohuID.ItemPrev:='<li>';
SohuID.ItemRear:='</li>';
SohuID.LinkPrev:='href=';
SohuID.LinkRear:=' target=_blank>';
SohuID.HeadPrev:='<span class=p14>';
SohuID.HeadRear:='</span>';
SohuID.ContentPrev:='<br> ';
SohuID.ContentRear:=' <br>';
SohuID.Source:='搜狐';
//調(diào)用搜索過程進行第二次搜索
Search(SohuID);
end;
procedure TYahooSearch.Execute;
begin
//設(shè)定標識符記錄結(jié)構(gòu)體
YahooID.URl:='http://cn.search.yahoo.com/search/cn?h=S&';
YahooID.TotalPrev:='共找到'+#$A+'<b class="yge">';
YahooID.TotalRear:=' </b>個</td>';
YahooID.KeywordID:='p';
YahooID.PageID:='b';
YahooID.ItemAmountPerPage:=20;
YahooID.PageIndex:=20;
YahooID.PageBegin:=1;
YahooID.HasNO:=False;
YahooID.ItemPrev:='<big>';
YahooID.ItemRear:='<small>';
YahooID.LinkPrev:='href="';
YahooID.LinkRear:='" target="_blank">';
YahooID.HeadPrev:='" target="_blank">';
YahooID.HeadRear:='</a></big>';
YahooID.ContentPrev:='- ';
YahooID.ContentRear:='<br>';
YahooID.Source:='雅虎';
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -