g++ get.cpp -std=c++11 -stdlib=libc++
获取网址下子链接的地址:
--------
#include <iostream>
#include <fstream>
#include <string>
#include <regex>
#include <cstdlib>
using namespace std;
int main(){
string begin("<a href=\"");
string end("\">");
regex reg("><a href=\"([^(/|\?)].*?)(?=\">)");
string baseurl("http://www.opensource.apple.com/source/CF/CF-476.14/");
ifstream in("./a.html");
string line;
smatch file_match;
while (getline(in,line)) {
while (regex_search(line,file_match,reg)) {
for (size_t i = 1;i < file_match.size(); i ++) {
string name = file_match[i];
string url(baseurl + name + "?txt");
//cout<<name<<endl;
string cmd("curl ");
cmd.append(url);
cmd.append(" -o ");
cmd.append(name);
system(cmd.c_str());
}
line = file_match.suffix().str();
}
}
return 0;
}