網頁標題資訊採集

2021-08-27 12:16:10 字數 4074 閱讀 2367

!------------------------

之前做了乙個通過ip來掃瞄**的,以為能掃到所有的**,因為ip是能全部遍歷的,但是忘記了很多**是禁止反向解析的。

所以更改了寫法,仿照類似爬蟲的方法,抓取乙個網頁的內容,然後遍歷其中的**,然後根據其中的**再去遍歷內容,如此做了個簡單的網頁標題資訊採集工具.

--更新,1.使用多執行緒處理;2.使用快取技術減少db訪問;3.優化網頁編碼獲取;4.增加錯誤日誌記錄及錯誤**檢測

主要**如下:

using system;

using system.threading;

using system.collections.generic;

using system.windows.forms;

using system.linq;

using system.net;

using system.io;

using system.text;

using system.text.regularexpressions;

using system.data;

using system.data.oracleclient;

using system.collections;

namespace netcollect

static matchcollection geturl(string html)

static void main(string args)

dt = dbaccess.selectdb("select ip,url from net_collect ");//因為ip,url做的聯合主鍵,所以唯一標誌一條記錄

console.writeline("請輸入開始掃瞄的**(2個,逗號隔開):");

string url = console.readline();

string urlscan = url.split(',');//"www.265.com";

int count = 0;

logfile = new streamwriter("d:\\net_collectnew.log", true);

datetime starttime = datetime.now;

thread t = new thread(new parameterizedthreadstart(ipscan));

t.start(urlscan[0]);

thread t1 = new thread(new parameterizedthreadstart(ipscan));

t1.start(urlscan[1]);

while (true) ;

dbaccess.dbclose();

logfile.close();

timespan ts = datetime.now - starttime;

console.writeline("共掃瞄**:" + count + "個");

console.writeline("共掃瞄次數:" + counttimes + "次");

console.readkey();

}catch (exception ex)

}//使用多執行緒呼叫

static void ipscan(object obj)

/// /// 獲取頁面的html資訊,到標題()位置結束

///

/// 頁面位址

/// 超時時間,單位:ms

/// 編碼

if (addresslist.length != 0) urlinfo[0] = addresslist[0].tostring().trim();//獲取ip

else

counttimes++;

console.writeline("第[" + counttimes + "]次scan, url=" + url.replace("https://", "").replace("http://", ""));

//datatable dt=dbaccess.selectdb("select count(*) from net_collect where ip='"+urlinfo[0].tostring()+"' and url='"+url+"' ");

datarow dr = dt.select(@"ip='" + urlinfo[0].tostring() + "' and url='" + url.trimend('"').trimend('?').trimend('\'') + "' ");

if (dr.length>0&&count!=0)//遞迴終止條件

return null;

datatable dt1 = dbaccess.selectdb("select count(*) from net_collect where ip='" + urlinfo[0].tostring() + "' and url='" + url + "' ");

if (null == dt1)

if (dt1.rows[0][0].tostring() != "0" && count != 0)//遞迴終止條件

return null;

lock (url)//加鎖,防止重複寫入

if (urlinfo[0] != null && urlinfo[1] != "無法連線到遠端伺服器" && url!=null)

if(mc.count!=0)

foreach (match match in mc)

return urlinfo;

}catch (exception ex)

finally if (response != null) if (request != null) }

}static string gethtmlcode(string url)

return charset;}}

}}}}

else

return charset;}}

}}}webresponse.close();

webrequest.abort();

return charset;

}catch (exception ex)}}

}

執行如圖:

---日誌檔案部分內容如下:

網頁資訊採集實現

最近公司需要開發乙個簡歷匯入功能,類似部落格搬家或者郵箱搬家,之前抓取資訊是利用火車採集器,但是簡歷匯入功能需要使用者登陸以後才能獲取簡歷資料,無奈只好自己開發了。首先是遇到的問題是 如何實現模擬登陸?我們知道一般的 都是通過cookies來維護狀態的,我抓的 也是支援利用cookies來驗證使用者...

C 網頁資訊採集 資料訪問

using system using system.collections using system.collections.specialized using system.data using system.data.sqlclient using system.configuration pu...

網頁採集 PDO入庫

採集soho網頁新聞 header頭 header content type text html charset utf8 位址 url 獲取 內容 str file get contents url 轉碼 str iconv gbk utf 8 str pdo連線資料庫 pdo new pdo m...