C++利用BOOST和Wget提取百度图片实例

来源:互联网 发布:mac os 最新的版本号 编辑:程序博客网 时间:2024/05/22 10:34

本文转自.http://www.郭华.com/?p=235  转载请注明出处

作者: gh0716 / 2012年04月28日

C++利用BOOST和Wget提取百度图片实例。

只是作为一个简单的模型,没有其他目的。

由于临时写的,文件名和路径都很乱。抛砖引玉的作用。可以修改,做成其他批量工具。

转载、复制请注明出处http://www.xn--xkrx74l.com/?p=235

效果如下:

运行效果图

提取效果图:



源代码:

/* *作者:gh0716 *邮箱:gh0716@163.com *原理:boost分析网页 *网址:http://www.xn--xkrx74l.com/?p=235 *说明:需要配置boost和放置wget到exe目录,或者改写下载方式 *时间:2012年4月28日19:42:10 *目的:抛砖引玉*/#include<iostream>#include <boost/regex.hpp>#include <fstream>#include <UrlMon.h>#pragma comment(lib, "urlmon.lib")using namespace std;   using namespace boost;int main()   {       regex reg("objURL\\\":\\\"([^\\\'\\\"\\s?]+\\.jpg)\\s*", boost::regex::perl|boost::regex::icase);         smatch m;     HRESULT hr =URLDownloadToFile(0,"http://image.baidu.com/i?ct=201326592&cl=2&nc=1&lm=-1&st=-1&tn=baiduimage&istype=2&fm=index&pv=&z=0&word=%C3%C0%CD%BC&s=0","index.html", 0,NULL);if(hr==S_OK){fstream file2("index.lst",ios::out|ios::app);fstream file("index.html",ios::in);     string k;   string s;   while(!file.eof())   {   file >> k;   s += k;   }   string::const_iterator it = s.begin();     string::const_iterator end = s.end();     int n = 0;   while (boost::regex_search(it,end,m,reg))    {   n ++;   cout << m[1] << endl; file2<<m[1]<<endl;it = m[1].second;   }    cout <<"共匹配到 "<< n <<"个链接"<< endl;  file.close();file2.close();ShellExecute(NULL,"open","wget.exe" ,"-b -i index.lst -c",NULL,SW_HIDE);cout<<"OK"<<endl;}    return 0;   }      

说明,需要配置boost和复制wget等部分文件过来。

需要源码的可以留下邮箱。

 

 

本文转自.http://www.郭华.com/?p=235  转载请注明出处。


原创粉丝点击