首先我们每个人都想查对方的手机所在地及属于什么类型卡,那我们利用C#封装的类WebClient,NameValueCollection,Regex等分别属于的命名空间是using System.Net、using System.Text、using System.Collections.Specialized、using System.Text.RegularExpressions。是在Vs2005环境下测试,下面代码测试如下:
 1 private void InitWeaOne()
 private void InitWeaOne()
2 {
   {
3 WebClient wb = new WebClient();
       WebClient wb = new WebClient();
4 NameValueCollection myNameValueCollection = new NameValueCollection();
       NameValueCollection myNameValueCollection = new NameValueCollection();
5
6 myNameValueCollection.Add("mobile", "13777483912");
       myNameValueCollection.Add("mobile", "13777483912");
7 myNameValueCollection.Add("action", "mobile");
       myNameValueCollection.Add("action", "mobile");
8 byte[] pagedata = wb.UploadValues("http://www.ip138.com:8080/search.asp", myNameValueCollection);
       byte[] pagedata = wb.UploadValues("http://www.ip138.com:8080/search.asp", myNameValueCollection);
9 string result = Encoding.Default.GetString(pagedata);
       string result = Encoding.Default.GetString(pagedata);
10 string pat = "tdc2>([^<]*)</TD>";
       string pat = "tdc2>([^<]*)</TD>";
11 Regex r = new Regex(pat, RegexOptions.IgnoreCase);
       Regex r = new Regex(pat, RegexOptions.IgnoreCase);
12 Match m = r.Match(result);
       Match m = r.Match(result);
13 string[] strInfo = new string[3] { "", "", "" };
       string[] strInfo = new string[3] { "", "", "" };
14 int i = 0;
       int i = 0;
15 while (m.Success)
       while (m.Success)
16 {
       {
17 if (i < strInfo.Length)
           if (i < strInfo.Length)
18 {
           {
19 strInfo[i] = m.ToString().Substring(5);
               strInfo[i] = m.ToString().Substring(5);
20 }
           }
21 m = m.NextMatch();
           m = m.NextMatch();
22 i++;
           i++;
23 }
       }
24 string a = strInfo[0].ToString();
       string a = strInfo[0].ToString();
25 string g = strInfo[1].ToString();
       string g = strInfo[1].ToString();
26 string f = strInfo[2].ToString();
       string f = strInfo[2].ToString();
27 
   
28 }
  }
 private void InitWeaOne()
 private void InitWeaOne()2
 {
   {3
 WebClient wb = new WebClient();
       WebClient wb = new WebClient();4
 NameValueCollection myNameValueCollection = new NameValueCollection();
       NameValueCollection myNameValueCollection = new NameValueCollection();5

6
 myNameValueCollection.Add("mobile", "13777483912");
       myNameValueCollection.Add("mobile", "13777483912");7
 myNameValueCollection.Add("action", "mobile");
       myNameValueCollection.Add("action", "mobile");8
 byte[] pagedata = wb.UploadValues("http://www.ip138.com:8080/search.asp", myNameValueCollection);
       byte[] pagedata = wb.UploadValues("http://www.ip138.com:8080/search.asp", myNameValueCollection);9
 string result = Encoding.Default.GetString(pagedata);
       string result = Encoding.Default.GetString(pagedata);10
 string pat = "tdc2>([^<]*)</TD>";
       string pat = "tdc2>([^<]*)</TD>";11
 Regex r = new Regex(pat, RegexOptions.IgnoreCase);
       Regex r = new Regex(pat, RegexOptions.IgnoreCase);12
 Match m = r.Match(result);
       Match m = r.Match(result);13
 string[] strInfo = new string[3] { "", "", "" };
       string[] strInfo = new string[3] { "", "", "" };14
 int i = 0;
       int i = 0;15
 while (m.Success)
       while (m.Success)16
 {
       {17
 if (i < strInfo.Length)
           if (i < strInfo.Length)18
 {
           {19
 strInfo[i] = m.ToString().Substring(5);
               strInfo[i] = m.ToString().Substring(5);20
 }
           }21
 m = m.NextMatch();
           m = m.NextMatch();22
 i++;
           i++;23
 }
       }24
 string a = strInfo[0].ToString();
       string a = strInfo[0].ToString();25
 string g = strInfo[1].ToString();
       string g = strInfo[1].ToString();26
 string f = strInfo[2].ToString();
       string f = strInfo[2].ToString();27
 
   28
 }
  } 
                     
                    
                 
                    
                 
 
   
 
        
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号