資源簡介
VC++實現的網絡爬蟲程序,非常好,適合作為框架進行二次開發

代碼片段和文件信息
////////////////////////////////////////////////////
//?DownloadData.cpp:?implementation?of?the?DownloadData?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“NetCrawler.h“
#include?“afxmt.h“
#include?“DownloadData.h“
#ifdef?_DEBUG
#undef?THIS_FILE
static?char?THIS_FILE[]=__FILE__;
#define?new?DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
DownloadData::DownloadData()
{
uCur_URLnum=0; //初始化當前隊列中URL數量為0
uMaxSizeOfContainer=4000; //URL隊列最大容量
uCur_URLptr=0; //當前隊列頭部指針
uCur_ActiveThread=0; //當前活動線程數量為0
uMaxThreadNum=10; //初始化線程數目10
uCur_Fileid=1; //初始化本地文件名稱為1
str_LocalDir=“E:\\“; //初始化本地文件目錄為C:
}
DownloadData::~DownloadData()
{
}
//是否URL隊列已經滿了
bool?DownloadData::IsEmpty()
{
criSection.Lock();
bool?r=(uCur_URLnum<=uCur_URLptr);
criSection.Unlock();
return?r;
}
//是否URL已經存在于隊列中
bool?DownloadData::IsExisted(CString?&str)
{
criSection.Lock();
for(UINT?i=0;i {
if(URLcontainer[i]==str)
{
criSection.Unlock();
return?TRUE;
}
}
criSection.Unlock();
return?FALSE;
}
//是否URL隊列空了(無未處理的URL)
bool?DownloadData::IsFull()
{
criSection.Lock();
bool?r=(uCur_URLnum==uMaxSizeOfContainer);
criSection.Unlock();
return?r;
}
//獲得當前活動線程數目
UINT?DownloadData::GetCurThread()
{
criSection.Lock();
UINT?n=uCur_ActiveThread;
criSection.Unlock();
return?n;
}
//獲得最大線程數目
UINT?DownloadData::GetMaxThreadnum()
{
return?uMaxThreadNum;
}
//線程開始,向數據區添加一個線程記錄成功返回true
bool?DownloadData::AddThread()
{
criSection.Lock();
if(uCur_ActiveThread==uMaxThreadNum)
{
criSection.Unlock();
return?FALSE;
}
uCur_ActiveThread++;
criSection.Unlock();
return?TRUE;
}
//線程結束后,從數據區刪除一個線程記錄,成功返回true
bool?DownloadData::DeleThread()
{
criSection.Lock();
if(uCur_ActiveThread==0)
{
criSection.Unlock();
return?FALSE;
}
uCur_ActiveThread--;
criSection.Unlock();
return?TRUE;
}
//從共享數據區URL隊列頭取出一個URL
bool?DownloadData::GetCurURL(CString?&str)
{
criSection.Lock();
if(uCur_URLptr>=uCur_URLnum)
{
criSection.Unlock();
return?FALSE;
}
str=URLcontainer[uCur_URLptr];
uCur_URLptr++;
criSection.Unlock();
return?TRUE;
}
//向共享數據區URL隊列尾添加一個URL
bool?DownloadData::AddURL(CString?&str)
{
criSection.Lock();
if(uCur_URLnum==uMaxSizeOfContainer)
{
criSection.Unlock();
return?FALSE;
}
URLcontainer[uCur_URLnum]=str;
uCur_URLnum++;
criSection.Unlock();
return?FALSE;
}
//獲得當前本地存儲文件的地址
void?DownloadData::GetFileName(CString?&str)
{
criSection.Lock();
CString?str_temp;
str_temp.Format(“%d“uCur_Fileid);
str=str_LocalDir+str_temp+“.txt“;
uCur_Fileid++;
criSection.Unlock();
}
//根據用戶設定起始文件名稱,最大線程數量,保存路徑
bool?DownloadData::SetPro(UINT?Fileid?UINT?ThreadNum?CString?&str)
{
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????57856??2011-05-29?21:10??Crawler\NetCrawler.opt
?????文件???????2720??2011-05-29?21:10??Crawler\NetCrawler.clw
?????文件????????545??2004-12-13?23:33??Crawler\NetCrawler.dsw
?????文件?????107520??2011-05-29?21:10??Crawler\NetCrawler.ncb
?????文件???????1710??2011-05-15?19:20??Crawler\NetCrawler.plg
?????文件???????3651??2004-12-13?23:33??Crawler\ReadMe.txt
?????文件????????402??2004-12-13?23:33??Crawler\res\NetCrawler.rc2
????..A.SH.??????3072??2007-05-22?21:05??Crawler\res\Thumbs.db
?????文件???????1078??2011-05-13?10:39??Crawler\res\NetCrawler.ico
?????文件????????212??2004-12-13?23:33??Crawler\StdAfx.cpp
?????文件???????1054??2004-12-13?23:33??Crawler\StdAfx.h
?????文件???????3724??2011-05-13?10:40??Crawler\Release\NetCrawler.res
?????文件????7398396??2011-05-12?23:42??Crawler\Release\NetCrawler.pch
?????文件??????58368??2011-05-29?21:10??Crawler\Release\vc60.idb
?????文件????1537214??2011-05-12?23:42??Crawler\Release\StdAfx.sbr
?????文件????????786??2011-05-12?23:42??Crawler\Release\StdAfx.obj
?????文件??????????0??2011-05-13?12:51??Crawler\Release\DownloadData.sbr
?????文件??????????0??2011-05-15?19:20??Crawler\Release\MainThread.sbr
?????文件??????????0??2011-05-13?10:40??Crawler\Release\NetCrawler.sbr
?????文件??????????0??2011-05-13?10:40??Crawler\Release\NetCrawlerDlg.sbr
?????文件??????????0??2011-05-13?10:40??Crawler\Release\ProjectDlg.sbr
?????文件??????12471??2011-05-13?00:15??Crawler\Release\ProjectDlg.obj
?????文件??????25132??2011-05-13?10:40??Crawler\Release\NetCrawlerDlg.obj
?????文件??????12352??2011-05-13?10:40??Crawler\Release\NetCrawler.obj
?????文件??????32760??2011-05-15?19:20??Crawler\Release\MainThread.obj
?????文件??????11605??2011-05-13?12:51??Crawler\Release\DownloadData.obj
?????文件??????36864??2011-05-15?19:20??Crawler\Release\NetCrawler.exe
?????文件????4064256??2011-05-15?19:20??Crawler\Release\NetCrawler.bsc
?????文件???????4740??2011-05-13?00:51??Crawler\NetCrawler.dsp
?????文件???????1377??2011-05-13?10:39??Crawler\Resource.h
............此處省略19個文件信息
- 上一篇:數字圖像處理 的C++反色
- 下一篇:主站接收數據的101協議
評論
共有 條評論