c++boost库正则取网页数据输入

来源:互联网 发布:网络框架 编辑:程序博客网 时间:2024/06/05 11:59

             题外话:找工作有段时间了,我不后悔转到程序开发这条路。虽然现在很苦又不好找工作但是我在努力,虽然现在没公司要我,但是我相信一个有这么多经验及阅历且真心想做个好程序的人,一定能成为一个优秀的程序员。为自己加油打气相信今年一定会好起来的。

              1.boost库下载地址  :http://jaist.dl.sourceforge.net/project/boost/boost/1.35.0/boost_1_35_0.zip

               2.由于是源代码需要自己编译一下,因为我用的是VC6.0用cmd输入:nmake -fvc6.mak”boost\libs\regex\build\vc6.mak 如果提示没有nmake这个命令就执行VC98\Bin\VCVARS32.BAT 或者找到这nmake.exe这个可执行程序路径也可以。我编译大概用了二分钟。

               3.把编译好的路径,及头文个的路径在  菜单:工具->选项->目录中设置好    注意:Includefiles 和Libraryfilef都要设置。


完整源代码如下,在windowsXP下运行正常。

#include <urlmon.h>#pragma comment(lib, "urlmon.lib")#include <string>#include <iostream>#include <fstream>#include <boost/regex.hpp>using namespace std;int main(){//     URLDownloadToFile(0, "http://www.bwlc.net/bulletin/index.jsp?id=2&page=1", "bwlc.txt", 0, 0);    fstream fs("bwlc.txt", ios::in | ios::binary);    fs.seekg(0, ios::end);    int fileSize = fs.tellg();    fs.seekg(0, ios::beg);    string s(fileSize, ' ');    fs.read(&s[0], fileSize);    fs.close();boost::regex reg("\\s{13}<td>[\\d]{6}</td>\r\n\\s{24}<td>([\\d]{2},){9}[\\d]{2}</td>\r\n\\s{24}<td>[\\d]{4}-[\\d]{2}-[\\d]{2} [\\d]{2}:[\\d]{2}</td>");boost::sregex_iterator it(s.begin(),s.end(),reg);boost::sregex_iterator end;int i = 1;while (it!=end){cout << "--------------------------------------------------------------------"<<endl;cout <<"第"<<i++ << "行数据:"<<*it++<< endl;}    return 0;}







0 0