c# 代理IP获取通用方法
调用:
ConcurrentQueue<string> proxyIpQueue = new ConcurrentQueue<string>();
Grab_ProxyIp(proxyIpQueue);
返回结果:

一下是获取代理IP集合的方法:
#region 生产IP 代理 对象
private void Grab_ProxyIp(ConcurrentQueue<string> proxyIpQueue)
{
HashSet<string> proxyIp = new HashSet<string>(); HttpHelper http = new HttpHelper();
HttpItem para = new HttpItem();
para.Timeout = * ;
para.Method = "GET"; int count = ;
para.URL = "http://www.xicidaili.com/nn/1"; // 西刺
RetryFunc(() =>
{
HttpResult result = http.GetHtml(para);
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
string regex = @"<td>(\d+\.\d+\.\d+\.\d+)</td>\s+<td>(\d+)</td>";
Match mstr = Regex.Match(result.Html, regex);
while (mstr.Success && count < )
{
proxyIp.Add(mstr.Groups[].Value + ":" + mstr.Groups[].Value);
mstr = mstr.NextMatch();
count++;
} return true;
}
else
{
return false;
}
}, ); count = ;
para.URL = "http://ip84.com/dlgn"; // IP巴士
RetryFunc(() =>
{
HttpResult result = http.GetHtml(para);
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
string regex = @"<td>(\d+\.\d+\.\d+\.\d+)</td>\s+<td>(\d+)</td>";
Match mstr = Regex.Match(result.Html, regex);
while (mstr.Success && count < )
{
proxyIp.Add(mstr.Groups[].Value + ":" + mstr.Groups[].Value);
mstr = mstr.NextMatch();
count++;
} return true;
}
else
{
return false;
}
}, ); count = ;
para.URL = "http://www.ip3366.net/free/?stype=1"; // 云代理
RetryFunc(() =>
{
HttpResult result = http.GetHtml(para);
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
string regex = @"<td>(\d+\.\d+\.\d+\.\d+)</td>\s+<td>(\d+)</td>";
Match mstr = Regex.Match(result.Html, regex);
while (mstr.Success && count < )
{
proxyIp.Add(mstr.Groups[].Value + ":" + mstr.Groups[].Value);
mstr = mstr.NextMatch();
count++;
} return true;
}
else
{
return false;
}
}, ); count = ;
para.URL = "http://www.iphai.com/free/ng"; // IP海
RetryFunc(() =>
{
HttpResult result = http.GetHtml(para);
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
string regex = @"<td>\s+(\d+\.\d+\.\d+\.\d+)\s+</td>\s+<td>\s+(\d+)\s+</td>";
Match mstr = Regex.Match(result.Html, regex);
while (mstr.Success && count < )
{
proxyIp.Add(mstr.Groups[].Value + ":" + mstr.Groups[].Value);
mstr = mstr.NextMatch();
count++;
} return true;
}
else
{
return false;
}
}, ); count = ;
para.URL = "http://www.66ip.cn/nmtq.php?getnum=10&isp=0&anonymoustype=3&start=&ports=&export=&ipaddress=&area=1&proxytype=2&api=66ip"; // 66ip
RetryFunc(() =>
{
HttpResult result = http.GetHtml(para);
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
string regex = @"(\d+\.\d+\.\d+\.\d+):(\d+)<br/>";
Match mstr = Regex.Match(result.Html, regex);
while (mstr.Success && count < )
{
proxyIp.Add(mstr.Groups[].Value + ":" + mstr.Groups[].Value);
mstr = mstr.NextMatch();
count++;
} return true;
}
else
{
return false;
}
}, ); foreach (var item in proxyIp)
{
proxyIpQueue.Enqueue(item);
}
}
#endregion
c# 代理IP获取通用方法的更多相关文章
- 获取用户Ip地址通用方法常见安全隐患(HTTP_X_FORWARDED_FOR)
分析过程 这个来自一些项目中,获取用户Ip,进行用户操作行为的记录,是常见并且经常使用的. 一般朋友,都会看到如下通用获取IP地址方法. function getIP() { if (isset($_ ...
- python——代理ip获取
python爬虫要经历爬虫.爬虫被限制.爬虫反限制的过程.当然后续还要网页爬虫限制优化,爬虫再反限制的一系列道高一尺魔高一丈的过程. 爬虫的初级阶段,添加headers和ip代理可以解决很多问题. 贴 ...
- 获取用户Ip地址通用方法
1 public static function getIp() 2 { 3 if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]) 4 { ...
- 使用TaskManager爬取2万条代理IP实现自动投票功能
话说某天心血来潮想到一个问题,朋友圈里面经常有人发投票链接,让帮忙给XX投票,以前呢会很自觉打开链接帮忙投一票.可是这种事做多了就会考虑能不能使用工具来进行投票呢,身为一名程序猿决定研究解决这个问题. ...
- 反爬虫2(代理ip)
在进行爬虫访问时,被访问主机除了会校验访问身份,还会校验访问者的ip, 当短时间同ip大量访问时,主机有可能会拒绝 返回,所以就现需要代理ip, 百度中可以获取到大量的免费的代理ip(ps:注意在访问 ...
- python爬虫成长之路(二):抓取代理IP并多线程验证
上回说到,突破反爬虫限制的方法之一就是多用几个代理IP,但前提是我们得拥有有效的代理IP,下面我们来介绍抓取代理IP并多线程快速验证其有效性的过程. 一.抓取代理IP 提供免费代理IP的网站还挺多的, ...
- 写了个小爬虫,为何用上代理ip总是出现错误。
import urllib.request import re import os import random import threading def url_open(url): #在第8到第12 ...
- Shell curl 和 wget 使用代理IP
Linux Shell 提供两个非常实用的命令来爬取网页,它们分别是 curl 和 wget curl 和 wget 使用代理 curl 支持 http.https.socks4.socks5 wge ...
- C#多线程爬虫抓取免费代理IP
这里用到一个HTML解析辅助类:HtmlAgilityPack,如果没有网上找一个增加到库里,这个插件有很多版本,如果你开发环境是使用VS2005就2.0的类库,VS2010就使用4.0,以此类推.. ...
随机推荐
- Android(java)学习笔记78:设计模式之单例模式
单例模式代码示例: 1. 单例模式之饿汉式: package cn.itcast_03; public class Student { // 构造私有 private Student() { } // ...
- CSS skills: 2) change hover dynamically by js
//命名空间 var base = {}; //class base.gClass={}; //鼠标hover交互方法: 注册对象的hover的class特性以及mouseMoveIn,mouseMo ...
- python django第一天
django第一天,上一次是使用了virtualenv(沙盒),这一次就直接用virtualenv直接建一个django的环境,用来自己练着试试django: source django/Script ...
- Android 内存分析工具 MAT(Memory Analyzer Tool)
如果使用DDMS确实发现了我们的程序中存在内存泄漏,那又如何定位到具体出现问题的代码片段,最终找到问题所在呢?如果从头到尾的分析代码逻辑,那肯定 会把人逼疯,特别是在维护别人写的代码的时候.这里介绍一 ...
- T-SQL使用JOIN执行UPDATE语句
问题: In SQL Server, it's possible to insert into a table using a SELECT statement: INSERT INTO Table ...
- java内存被释放的小例子
先贴代码: StringBuilder dada = null; ; i<; i++){ dada = new StringBuilder(); ; j<; j++){ dada.appe ...
- NUI相关术语
分享一下微软资深企业架构师.应用开发专家余涛先生书中所谈到的相关术语,以便查阅,部分术语根据个人理解加入了细化内容: 1.波束形成算法(BeamformingAlgorithm) 基于现行阵列的阵列信 ...
- 备忘====[HttpPost]和[AcceptVerbs(HttpVerbs.Post)]区别
1.共同点:[HttpPost]和[AcceptVerbs(HttpVerbs.Post)]都是只接受POST请求过来的数据. 2.不同点:在MVC中如果想一个action既可以回应POST请求也可以 ...
- 使用TreeView+ListBox+TxtBox 资料管理器
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- OpenGL9-(FreeImage)加载图片-作为纹理
/*** 这个例子展示如何使用FreeImage加载图片作为纹理* 初学者,在学习OpenGL的时候,往往因为OpenGL读图片没有那么方便* 而浪费了大量的时间在研究图片格式上,其实大可不必. 1. ...