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);
        }
复制代码

 

 

 

posted @   leeolevis  阅读(419)  评论(1编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示