本文共 4417 字,大约阅读时间需要 14 分钟。
功能有待完善和添加
#include#include #include #include #include #include #include using namespace std;//通过Wget来获取网页string GetHtmlByWget(string url){ //获取待下载网页文件名 string fileName = url.substr((int)url.find_last_of("/") + 1); if(fileName != "") { string strCom = "wget -q "; //wget命令,-q表示不显示下载信息 strCom.append(url); system(strCom.c_str()); //执行wget ifstream fin(fileName.c_str()); if(!fin) { return ""; } string strHtml = ""; char chTemp[1024] = ""; //读取网页文件到内存中 while(fin.getline(chTemp , 1024)) { strHtml.append(string(chTemp)); strcpy(chTemp , ""); } fin.close(); strCom = "del -f "; //删除文件命令,-f表示直接删除不做任何提示 strCom.append(fileName); system(strCom.c_str()); //删除刚才下载下来的文件 return strHtml; //返回网页源码 } else { return ""; }}string GetHtmlPath(int y, int m, int d){ stringstream str; string now; string path = "http://www.nod32jihuoma.cn/nod32-id/"; str << y + 1900; str >> now; path.append(now); path.append("-"); now.clear(); str.clear(); int month = m + 1; if(month / 10 == 0) { str << 0; str >> now; path.append(now); now.clear(); str.clear(); } str << month; str >> now; path.append(now); path.append("-"); now.clear(); str.clear(); int day = d; if(day / 10 == 0) { str << 0; str >> now; path.append(now); now.clear(); str.clear(); } str << day; str >> now; path.append(now); path.append(".html"); now.clear(); str.clear(); return path;}void SearchData(int n){ ofstream cout("key.txt"); const string key = " 用户名:";//13 const string value = " 密 码:";//14 time_t t = time(NULL); struct tm* cur = localtime(&t); int y = cur->tm_year; int m = cur->tm_mon; int d = cur->tm_mday; for(int i = 0 ; i < n; i++) { int dd = d - i; string path = GetHtmlPath(y, m, dd); cout << "获取网址" << "\n" << path << endl; string data = GetHtmlByWget(path); //cout << data << endl; cout << y + 1900 << "年" << m + 1 << "月" << dd << "日 " << endl; cout << "用户名: 密码:" <
效果图:
由于获取NOD32激活码的网址更改为http://www.nod32jihuoma.cn/nod32-id/index.html
即不需要网址最后的时间的处理了,变得更加简单化
相应的代码更改为:
#include#include #include #include #include #include #include #include using namespace std;string GetHtml(CString url){ CString content; CString data; DWORD dwStatusCode; CInternetSession session("HttpClient"); CHttpFile* pfile = (CHttpFile *)session.OpenURL(url); pfile -> QueryInfoStatusCode(dwStatusCode); if(dwStatusCode == HTTP_STATUS_OK) { while (pfile -> ReadString(data)) { content += data; } } pfile -> Close(); delete pfile; session.Close(); return string(content.GetBuffer(content.GetLength()));}void SearchData(){ ofstream cout("key.txt"); const string key = " 用户名:";//15 const string value = " 密 码:";//14 time_t t = time(NULL); struct tm* cur = localtime(&t); int y = cur->tm_year; int m = cur->tm_mon; int d = cur->tm_mday; string path = "http://www.nod32jihuoma.cn/nod32-id/index.html"; cout << "获取网址" << "\n" << path << endl; CString url; url.Format("%s",path.c_str()); string data = GetHtml(url); //cout << data << endl; cout << y + 1900 << "年" << m + 1 << "月" << d << "日 " << endl; cout << "用户名: 密码:" <
http://www.nod32jihuoma.cn/nod32-id/index.html
#include#include #include #include #include #include #include using namespace std;//通过Wget来获取网页string GetHtmlByWget(string url){ //获取待下载网页文件名 string fileName = url.substr((int)url.find_last_of("/") + 1); if(fileName != "") { string strCom = "wget -q "; //wget命令,-q表示不显示下载信息 strCom.append(url); system(strCom.c_str()); //执行wget ifstream fin(fileName.c_str()); if(!fin) { return ""; } string strHtml = ""; char chTemp[1024] = ""; //读取网页文件到内存中 while(fin.getline(chTemp , 1024)) { strHtml.append(string(chTemp)); strcpy(chTemp , ""); } fin.close(); strCom = "del -f "; //删除文件命令,-f表示直接删除不做任何提示 strCom.append(fileName); system(strCom.c_str()); //删除刚才下载下来的文件 return strHtml; //返回网页源码 } else { return ""; }}void SearchData(){ ofstream cout("key.txt"); const string key = " 用户名:";//15 const string value = " 密 码:";//14 time_t t = time(NULL); struct tm* cur = localtime(&t); int y = cur->tm_year; int m = cur->tm_mon; int d = cur->tm_mday; string path = "http://www.nod32jihuoma.cn/nod32-id/index.html"; cout << "获取网址" << "\n" << path << endl; string data = GetHtmlByWget(path); //cout << data << endl; cout << y + 1900 << "年" << m + 1 << "月" << d << "日 " << endl; cout << "用户名: 密码:" <
转载地址:http://koyhj.baihongyu.com/