Asp.net data collection base class (Remote capturing, decomposition, storage, and matching)
Detailed reference address: http://www.opent.cn/article.asp? Id = 5
# Region date Random Function
/**********************************
* Function name: DateRndName
* Function Description: Date Random Function
* Parameter: ra: Random Number
* Call example:
* GetRemoteObj o = new GetRemoteObj ();
* Random ra = new Random ();
* String s = o. DateRndName (ra );
* Response. Write (s );
* O. Dispose ();
*********************************/
/// <Summary>
/// Date Random Function
/// </Summary>
/// <Param name = "ra"> random number </param>
/// <Returns> </returns>
Public string DateRndName (Random ra)
{
DateTime d = DateTime. Now;
String s = null, y, m, dd, h, mm, ss;
Y = d. Year. ToString ();
M = d. Month. ToString ();
If (m. Length <2) m = "0" + m;
Dd = d. Day. ToString ();
If (dd. Length <2) dd = "0" + dd;
H = d. Hour. ToString ();
If (h. Length <2) h = "0" + h;
Mm = d. Minute. ToString ();
If (mm. Length <2) mm = "0" + mm;
Ss = d. Second. ToString ();
If (ss. Length <2) ss = "0" + ss;
S + = y + m + dd + h + mm + ss;
S + = ra. Next (100,999). ToString ();
Return s;
}
# Endregion
# Region obtain the file suffix
/**********************************
* Function name: GetFileExtends
* Function Description: Obtain the file suffix.
* Parameter: filename: File Name
* Call example:
* GetRemoteObj o = new GetRemoteObj ();
* String url = @ "http://www.baidu.com/img/logo.gif ";
* String s = o. GetFileExtends (url );
* Response. Write (s );
* O. Dispose ();
*********************************/
/// <Summary>
/// Obtain the file suffix
/// </Summary>
/// <Param name = "filename"> file name </param>
/// <Returns> </returns>
Public string GetFileExtends (string filename)
{
String ext = null;
If (filename. IndexOf ('.')> 0)
{
String [] fs = filename. Split ('.');
Ext = fs [fs. Length-1];
}
Return ext;
}
# Endregion
# Region obtain remote file source code
/**********************************
* Function name: GetRemoteHtmlCode
* Function Description: Obtain the remote file source code.
* Parameter: Url: remote url
* Call example:
* GetRemoteObj o = new GetRemoteObj ();
* String url = @ "http://www.baidu.com ";
* String s = o. GetRemoteHtmlCode (url );
* Response. Write (s );
* O. Dispose ();
*********************************/
/// <Summary>
/// Obtain the remote file source code
/// </Summary>
/// <Param name = "url"> remote url </param>
/// <Returns> </returns>
Public string GetRemoteHtmlCode (string Url)
{
String s = "";
MSXML2.XMLHTTP _ xmlhttp = new MSXML2.XMLHTTPClass ();
_ Xmlhttp. open ("GET", Url, false, null, null );
_ Xmlhttp. send ("");
If (_ xmlhttp. readyState = 4)
{
S = System. Text. Encoding. Default. GetString (byte []) _ xmlhttp. responseBody );
}
Return s;
}
# Endregion
The preceding examples of getting HTML code on the page have provided a lot of examples.
The following code uses a regular expression to retrieve HTML content
Regex regex1 = new Regex (this. NameKey, RegexOptions. Singleline | RegexOptions. IgnoreCase );
MatchCollection collection1 = regex1.Matches (this. Arthur TML );
If (collection1.Count> 0)
{
Result = collection1 [0]. Result ("$ {title }");
}