c++ 调用 wget 下载网页图片
2015-03-15 17:53
519 查看
这是一个c++调用wget下载图片的小程序, 可以结合我前一篇博客, 自动下载网页图片。
这是1.txt
#include <stdlib.h> #include <stdio.h> #include <iostream> using namespace std; #include <windows.h> #include <string> #include <vector> //file name max length #define getFolderFile_max_length 1024 //dfs bool dfsFolder(string rootPath, vector<string> &fileList, vector<FILETIME> &timelist) { WIN32_FIND_DATA findData; HANDLE hError; //构造路径 char nowPath[getFolderFile_max_length]; strcpy(nowPath, rootPath.c_str()); strcat(nowPath, "\\*.*"); //文件名 char fileName[getFolderFile_max_length]; hError = FindFirstFile(nowPath, &findData); if (hError == INVALID_HANDLE_VALUE) { printf("搜索失败!"); return false; } while (::FindNextFile(hError, &findData)) { //过虑.和.. if (strcmp(findData.cFileName, ".") == 0 ||strcmp(findData.cFileName, "..") == 0) continue; // FILETIME ftCreate, ftAccess, ftWrite; // GetFileTime(hError, &ftCreate, &ftAccess, &ftWrite); FILETIME ttt = findData.ftLastWriteTime; timelist.push_back(ttt); //构造完整文件名 sprintf(fileName, "%s\\%s", rootPath.c_str(), findData.cFileName); fileList.push_back(string(fileName)); //深度遍历递归,不是&&,可能是与操作 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { //弹出文件夹 fileList.pop_back(); // fileList.push_back(string(fileName)); dfsFolder(string(fileName), fileList, timelist); } } return true; } void bubblesort(vector<string> &fileList, vector<FILETIME> &unsorted) { for (int i = 0; i < unsorted.size(); i++) { for (int j = i; j < unsorted.size(); j++) { if (CompareFileTime(&unsorted[i], &unsorted[j]) == 1) { FILETIME temp = unsorted[i]; unsorted[i] = unsorted[j]; unsorted[j] = temp; string temp2 = fileList[i]; fileList[i] = fileList[j]; fileList[j] = temp2; } } } } int main() { string path = "1"; int beginindex = 1; vector<string> filefolderlist; vector<FILETIME> timelist; dfsFolder(path, filefolderlist, timelist); bubblesort(filefolderlist, timelist); for (int i = 0; i< filefolderlist.size(); i++) { int index = beginindex+i-1; string name = filefolderlist[i]; string truename = name.substr(name.find_last_of('\\')+1, name.find_last_of('.')-1 - name.find_last_of('\\')); char cmd[256]; sprintf(cmd, "mkdir \"%d_%s\"", index, truename.c_str()); int su = system(cmd); if (!su) { sprintf(cmd, "wget -P \"%d_%s\" -i \"%s\"", index, truename.c_str(), filefolderlist[i].c_str()); system(cmd); } else { cout<< index<<filefolderlist[i]<<endl; system("pause"); } } return 0; }
这是1.txt
http://i0.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09462.jpg http://i0.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09462.jpg http://i1.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09495.jpg http://i1.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09495.jpg http://i2.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09504.jpg http://i2.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09504.jpg http://i1.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09506.jpg http://i1.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09506.jpg http://i1.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09510.jpg http://i1.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09510.jpg http://i0.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09514.jpg http://i0.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09514.jpg http://i2.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09522.jpg http://i2.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09522.jpg http://i1.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09544.jpg http://i1.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09544.jpg http://i2.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09558.jpg http://i2.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09558.jpg http://i0.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09565.jpg http://i0.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09565.jpg http://i0.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09704.jpg http://i0.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09704.jpg http://i2.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09706.jpg http://i2.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09706.jpg http://i2.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09601.jpg http://i2.wp.com/heru3.com/wp/wp-content/uploads/2014/12/web_09601.jpg[/code]
相关文章推荐
- 保存网页为图片!GreenBrowser新功能(提供下载)
- 踏破铁鞋无觅处:网页下载图片的代码
- 如何找到网页图片地址并下载到本地保存?
- 利用wget 抓取 网站网页 包括css背景图片
- VC 从网页上下载图片
- 随便写的一个python小程序,从网页中下载图片
- WebClient下载网页图片
- 网页上图片禁止下载
- 在网页中调用www.panoramio.com网站的图片的几种方法
- wget下载网页
- 下载网页中的图片
- 如何提高网页中图片显示的用户体验(附源码下载)
- 下载网页中远程图片的方法
- JS中实现网页中禁止下载图片
- 可下载目标网页上的所有图片代码
- 下载网页中的图片
- 自己写个从网页里下载图片的程序
- 下载网页中远程图片的方法
- 用正则表达式自动下载网页中的图片
- 用正则表达式自动下载网页中的图片