Using ASP. Net to get all the links in the page

Time:2021-10-19

private void Page_Load(object sender, System.EventArgse) 
  { 
   // Place the user code here to initialize the page  

   string url =https://www.jb51.net; 
   System.Net.HttpWebRequesthttpReq; 
   System.Net.HttpWebResponsehttpRes; 
   System.UrihttpURL = new Uri(url); 
   httpReq =(System.Net.HttpWebRequest)System.Net.WebRequest.Create(httpURL); 
   httpReq.Method= “GET”; 
   httpRes= (System.Net.HttpWebResponse)httpReq.GetResponse(); 
   httpReq.KeepAlive= false; 
   System.IO.StreamReadersReader = newSystem.IO.StreamReader(httpRes.GetResponseStream(),System.Text.Encoding.GetEncoding(“GB2312”)); 
   stringres = sReader.ReadToEnd(); 
   // The following is to filter the obtained text stream using regular expressions  
   stringstrRegex = @”<a.+?a>”; 
   System.Text.RegularExpressions.Regexr; 
   System.Text.RegularExpressions.MatchCollectionm; 
   r = newSystem.Text.RegularExpressions.Regex(strRegex,System.Text.RegularExpressions.RegexOptions.IgnoreCase); 
   m =r.Matches(res); 
    Response. Write (“total of this page” + m.count  +  ”   Hyperlinks < br / > “);  
   for (inti = 0; i < m.Count; i++) 
   { 
    Response.Write(m[i].Value+ “<br/>”); 
   } 
  } 

Recommended Today

SQL statement of three-level linkage of provinces, cities and counties

The first is the table creation statement Copy codeThe code is as follows: CREATE TABLE `t_address_province` ( `id` INT AUTO_ Increment primary key comment ‘primary key’,`Code ` char (6) not null comment ‘province code’,`Name ` varchar (40) not null comment ‘province name’)Engine = InnoDB default charset = utf8 comment = ‘province information table’; CREATE TABLE […]