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,以此类推.. ...
随机推荐
- cocos2d-x回收池原理
cocos2d-x源于cocos2d-iphone,为了与Objective-c一致,cocos2d-x也采用了引用计数与自动回收的内存管理机制. 要现实自动内存回收,需继承于cocos2d-x的根类 ...
- MSSQL系统表常用操作
1:获取当前数据库中的所有用户表 select Name from sysobjects where xtype='u' and status>=0 2:获取某一个表的所有字段 select n ...
- Umbraco入门(一)--在VS中安装Umbraco
在VS中安装Umbraco 由于Vs中自己集成的IIS,所以在安装Umbraco是不用再想以前那么麻烦,需要设置IIS等等…… 使用VS的NuGet程序包管理器 创建一个用空的ASP Web应用程 ...
- Halcon C++混合编程学习之Qt 实现检测焊接点
1 # include "HalconCpp.h" # include "HDevThread.h" # include <X11/Xlib.h> ...
- linux下 cmatrix的安装和使用
安装过程 wget http://www.asty.org/cmatrix/dist/cmatrix-1.2a.tar.gztar xvf cmatrix-1.2a.tar.gzcd cmatrix- ...
- [改善Java代码]避免带有变长参数的方法重载
建议4: 避免带有变长参数的方法重载 在项目和系统的开发中,为了提高方法的灵活度和可复用性,我们经常要传递不确定数量的参数到方法中,在Java 5之前常用的设计技巧就是把形参定义成Collection ...
- 用bat使用date和time命令
D:\>date /T 2010-12-10 星期五 D:\>echo %date:~0,10% 2010-12-10 date:命令(别忘记date后面有个冒号) ~0:从索引0开始取内 ...
- java-MySQL存储过程
import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import ...
- poj2243
Knight Moves Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13433 Accepted: 7518 Des ...
- EWM Matrai B2B管理平台
该应用是一款企业管理的app,可以通过“分享”.“工作分派”.“审批”.“业务”.“工作计划”.“日程”等功能得到有效的管控.该项目主要分为5大模块,分别是近期动态,任务,日程,我,在线聊天.