zoukankan      html  css  js  c++  java
  • 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);
            }
  • 相关阅读:
    jxl切割excel文件
    Oracle 11g新增not null的字段比10g快--新特性
    再按一次退出程序
    项目进阶 之 集群环境搭建(一)概述
    分布式搜索elasticsearch 环境搭建
    WikiCFP--A Wiki for Calls For Papers
    Java的结构之美【2】——销毁对象
    Java的结构之美【1】——构造对象
    Bottle 中文文档
    我的算法学习之路
  • 原文地址:https://www.cnblogs.com/leeolevis/p/1754211.html
Copyright © 2011-2022 走看看