• FireBug结合System.Net的数据抓取


      以前一直用微软的Fiddler,现在受同事飞鸟(前端)的影响开始用FireFox的FireBug了,在此记录一下

      打开FireFox,F12开启Firebug,在IP138的搜索页面搜一条合法数据 

       

      以前URL好像不显示参数的,不过也好,看起来直观-。-

      1         ASCIIEncoding encoding = new ASCIIEncoding();

     2         string postData = "ip=" + strId;
     3         postData += ("&action=" + strPassword);
     4 
     5         byte[] data = encoding.GetBytes(postData);
     6 
     7         HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://www.ip138.com/ips.asp");
     8 
     9         myRequest.Method = "POST";
    10         myRequest.ContentType = "application/x-www-form-urlencoded";
    11         myRequest.ContentLength = data.Length;
    12         Stream newStream = myRequest.GetRequestStream();
    13 
    14         newStream.Write(data, 0, data.Length);
    15         newStream.Close();
    16 
    17         HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
    18         StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
    19         string content = reader.ReadToEnd();

      查询出来的结果

       

      将结果保存到文本文档中

            static void TestIP()
            {
                
    string filePath = @"d:\Ips.txt";
                
    string strIp = string.Empty;
                
    string strAd = string.Empty;
                Random r 
    = new Random();
                TestClass tc 
    = new TestClass();
                FileInfo fi 
    = new FileInfo(filePath);
                System.Diagnostics.Stopwatch sw
    =new System.Diagnostics.Stopwatch();sw.Start();
                
    for (int i = 1; i < 1001; i++)
                {
                    
    int ip1 = r.Next(100255);
                    
    int ip2 = r.Next(0255);
                    
    int ip3 = r.Next(0255);
                    
    int ip4 = r.Next(0255);
                    
                    strIp 
    = ip1.ToString() + "." + ip2.ToString() + "." + ip3.ToString() + "." + ip4.ToString();
                    strAd 
    = tc.GetAddressByIp(strIp);             

                    
    using (FileStream fs = new FileStream(filePath, FileMode.Append))
                    
    using (TextWriter tw = new StreamWriter(fs))
                    {
                        tw.WriteLine(
    "(" + i.ToString() + "" + strIp + " " + strAd);
                    }
                    Console.WriteLine(
    "" + i.ToString() + "次抓取成功");
                }
                sw.Stop();
                Console.WriteLine(
    "总共抓取时间耗时:"+sw.ElapsedMilliseconds.ToString());
                System.Diagnostics.Process.Start(filePath);
            }
  • 相关阅读:
    Educational Codeforces Round 81 (Rated for Div. 2)(训练)
    Prime Path(POJ) 3126
    前端知识(一)04 Vue.js入门-谷粒学院
    前端知识(一)03 初识 ECMAScript 6-谷粒学院
    前端知识(一)02 初识 Node.js-谷粒学院
    前端知识(一)01 前端开发和前端开发工具-谷粒学院
    同步和异步、阻塞和非阻塞
    给HTML页面设置自己的icon
    解决MyBatis-Plus 3.3.1中自动生成代码tinyint(1)无法自动转换为Boolean 的办法
    驼峰命名和短横线命名的转换
  • 原文地址:https://www.cnblogs.com/leeolevis/p/1754211.html
Copyright © 2020-2023  润新知