標籤:
採集資料來源:http://www.sgcc.com.cn/xwzx/gsyw/
//根據URL地址擷取所有html public static string GetUrltoHtml(string Url, string type) { try { System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url); // Get the response instance. System.Net.WebResponse wResp = wReq.GetResponse(); System.IO.Stream respStream = wResp.GetResponseStream(); // Dim reader As StreamReader = New StreamReader(respStream) using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding(type))) { return reader.ReadToEnd(); } } catch (System.Exception ex) { //errorMsg = ex.Message; } return ""; }
/// <summary> /// GetSubString截取字串 /// </summary> /// <param name="strSource">原始字元</param> /// <param name="strIndexOf">開始字元</param> /// <param name="strLastOf">結束字元</param> /// <returns></returns> public static string GetSubString(string strSource, string strIndexOf, string strLastOf) { string strResult = string.Empty; int indexOf = strSource.IndexOf(strIndexOf); if (indexOf > -1) { string strTemp = strSource.Substring(indexOf + strIndexOf.Length); if (!string.IsNullOrEmpty(strTemp)) { strResult = strTemp.Substring(0, strTemp.IndexOf(strLastOf)); } } return strResult; }
採集網頁資料產生到靜態模板newslist.html檔案中(Regex)