模擬網絡爬蟲

/*
利用wget  指令和隊列 模擬實現網絡爬蟲
利用自己的站點wzsts.host3v.com測試了一下
有一點錯誤
文件運行後拿到index.html
對於連接僅僅可以拿到 html 和htm 結尾的 而.com的沒有考慮(設計文件可能多)
一次測試後瞭解到如下問題:
1.文件應該有樹形話還原網站目錄
2.文本記錄的連接應該分類化
項目運行需要 su 根權限進行 
因爲mv命令
本項目僅僅適合在linux下運行
本項目給真真的linux 爬蟲做鋪墊
*/
#include<bits/stdc++.h>
using namespace std;
#include <stdlib.h>
#include <iostream>
#include <fstream>
string s("index.html");
queue<string>q;
 //略去一段
int main()
{
 //index.html
system("wget wzsts.host3v.com");

ofstream out("out.txt"); 
string mv("mv ");
string html(" html");
q.push(s);
  while(!q.empty())
   {
out<<q.front().c_str();   out<<"\n";  
if(strstr(q.front().c_str(),".html")||strstr(q.front().c_str(),".htm"))
  {
    fun(q.front().c_str()); 
    q.pop();
    string t("wget ");   t=t+s;  cout<<t.c_str()<<endl;
   system(t.c_str());
  }

string ss(q.front().c_str());
 ss=mv+ss.c_str()+html;     cout<<ss<<endl;
 system(ss.c_str());
   }

 out.close(); 
return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章