📄 unitsearch.pas
字号:
unit UnitSearch;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables, IdHTTP, ADODB;
//定义标识符记录结构体,用作参数传到Search函数
type
TIdentifier = Record
//要进行搜索的地址
URL:string;
//搜索结果总数的前面的字符串和后面的字符串
TotalPrev,TotalRear:string;
//每一页显示的项目数
ItemAmountPerPage:Integer;
//翻页参数,函数式为 i*PageIndex+PageBegin
PageIndex,PageBegin:Integer;
//关键字和翻页的参数名
KeywordID,PageID:string;
//在代码中是否存在数字序号
HasNO:Boolean;
//一个记录的开始标识符和结束标识符
ItemPrev,ItemRear:string;
//链接的开始标识符和结束标识符
LinkPrev,LinkRear:string;
//标题的开始标识符和结束标识符
HeadPrev,HeadRear:string;
//内容的开始标识符和结束标识符
ContentPrev,ContentRear:string;
//搜索结果的来源
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;
//构造每个搜索类线程
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;
//定义每个线程的执行操作
procedure TBaiduSearch.Execute;
begin
//设定标识符记录结构体
BaiduID.URL:='http://www.baidu.com/baidu?';
BaiduID.TotalPrev:='找到相关网页约';
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:='百度';
//调用搜索过程进行搜索
Search(BaiduID);
end;
procedure TGoogleSearch.Execute;
begin
//
end;
procedure T_21cnSearch.Execute;
begin
//设定标识符记录结构体
_21cnID.URL:='http://cha.21cn.com/result_all.php?tn=21cn&';
_21cnID.TotalPrev:='21cn搜索为您找到 <font color="#FF0000">';
_21cnID.TotalRear:='</font>'; //'</font> 个有关'; // #$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';
//调用搜索过程进行第一次搜索
Search(_21cnID);
//设定标识符记录结构体
_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';
//调用搜索过程进行第二次搜索
Search(_21cnID);
end;
procedure TSinaSearch.Execute;
begin
//设定标识符记录结构体
SinaID.URL:='http://search.sina.com.cn/cgi-bin/search/search.cgi?';
SinaID.TotalPrev:='相关网站 ';
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:='新浪';
//调用搜索过程进行第一次搜索
Search(SinaID);
//设定标识符记录结构体
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:='新浪';
//调用搜索过程进行第二次搜索
Search(SinaID);
end;
procedure TSohuSearch.Execute;
begin
//设定标识符记录结构体
SohuID.URL:='http://site.search.sohu.com/website.jsp?';
SohuID.TotalPrev:='共找到 '; //'网站搜索中共有 ';
SohuID.TotalRear:=' 个结果';
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:='<br>'+#$D+'</font>';
SohuID.Source:='搜狐';
//调用搜索过程进行第一次搜索
Search(SohuID);
//设定标识符记录结构体
SohuID.URL:='http://page.search.sohu.com/cgi-bin/pagesearch.cgi?';
SohuID.TotalPrev:='网页搜索中共有 ';
SohuID.TotalRear:=' 个查询结果';
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:='搜狐';
//调用搜索过程进行第二次搜索
Search(SohuID);
end;
procedure TYahooSearch.Execute;
begin
//设定标识符记录结构体
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 + -