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();
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(100, 255);
int ip2 = r.Next(0, 255);
int ip3 = r.Next(0, 255);
int ip4 = r.Next(0, 255);
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);
}
{
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(100, 255);
int ip2 = r.Next(0, 255);
int ip3 = r.Next(0, 255);
int ip4 = r.Next(0, 255);
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);
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现