调用:

       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获取通用方法的更多相关文章

  1. 获取用户Ip地址通用方法常见安全隐患(HTTP_X_FORWARDED_FOR)

    分析过程 这个来自一些项目中,获取用户Ip,进行用户操作行为的记录,是常见并且经常使用的. 一般朋友,都会看到如下通用获取IP地址方法. function getIP() { if (isset($_ ...

  2. python——代理ip获取

    python爬虫要经历爬虫.爬虫被限制.爬虫反限制的过程.当然后续还要网页爬虫限制优化,爬虫再反限制的一系列道高一尺魔高一丈的过程. 爬虫的初级阶段,添加headers和ip代理可以解决很多问题. 贴 ...

  3. 获取用户Ip地址通用方法

    1 public static function getIp() 2 { 3 if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]) 4 { ...

  4. 使用TaskManager爬取2万条代理IP实现自动投票功能

    话说某天心血来潮想到一个问题,朋友圈里面经常有人发投票链接,让帮忙给XX投票,以前呢会很自觉打开链接帮忙投一票.可是这种事做多了就会考虑能不能使用工具来进行投票呢,身为一名程序猿决定研究解决这个问题. ...

  5. 反爬虫2(代理ip)

    在进行爬虫访问时,被访问主机除了会校验访问身份,还会校验访问者的ip, 当短时间同ip大量访问时,主机有可能会拒绝 返回,所以就现需要代理ip, 百度中可以获取到大量的免费的代理ip(ps:注意在访问 ...

  6. python爬虫成长之路(二):抓取代理IP并多线程验证

    上回说到,突破反爬虫限制的方法之一就是多用几个代理IP,但前提是我们得拥有有效的代理IP,下面我们来介绍抓取代理IP并多线程快速验证其有效性的过程. 一.抓取代理IP 提供免费代理IP的网站还挺多的, ...

  7. 写了个小爬虫,为何用上代理ip总是出现错误。

    import urllib.request import re import os import random import threading def url_open(url): #在第8到第12 ...

  8. Shell curl 和 wget 使用代理IP

    Linux Shell 提供两个非常实用的命令来爬取网页,它们分别是 curl 和 wget curl 和 wget 使用代理 curl 支持 http.https.socks4.socks5 wge ...

  9. C#多线程爬虫抓取免费代理IP

    这里用到一个HTML解析辅助类:HtmlAgilityPack,如果没有网上找一个增加到库里,这个插件有很多版本,如果你开发环境是使用VS2005就2.0的类库,VS2010就使用4.0,以此类推.. ...

随机推荐

  1. CSS拾遗+技巧集合

    1.实现尖角符号. 这是内联inline-block标签独有的特性. <!DOCTYPE html> <html lang="en"> <head&g ...

  2. jqcss选择器

    $("p").css("background-color","red"); $(this) 当前 HTML 元素$("p" ...

  3. Simple Membership 学习笔记

    第一步:新建项目后添加对WebMartix.Data 和 WebMatrix.WebData的引用第二步:在web.config中添加membership配置节第三步:修改Global.asax文件 ...

  4. 使用copy再次实现Circle类,保证不能有内存泄漏问题

    #import <Foundation/Foundation.h> //xieyi @protocol showOn @required -(void)printOn; @end // l ...

  5. linux-软连接

    ln -s /opt/lampp/bin/mysql(绝对路径) /usr/local/bin(软连接目录或者文件) 如果不愿意配置环境变脸可以直接创建env查出的路径下建连接

  6. 【数值方法,水题】UVa 10341 - Solve It

    题目链接 题意: 解方程:p ∗ e^(−x) + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x^2 + u = 0 (0 <= x <= 1) ...

  7. Spring 简单入门实例

    首先新建一个Web 项目 导入相应Jar 包 <?xml version="1.0" encoding="UTF-8"?> <beans xm ...

  8. .NET平台数据持久层框架

    在.NET平台下的几个数据持久层框架: 1.NHibernate 2.NBear 3.Castle ActiveRecord 4.iBATIS.NET 5.DAAB 6.DLinq

  9. EWM Matrai B2B管理平台

    该应用是一款企业管理的app,可以通过“分享”.“工作分派”.“审批”.“业务”.“工作计划”.“日程”等功能得到有效的管控.该项目主要分为5大模块,分别是近期动态,任务,日程,我,在线聊天.   

  10. Win10开机小键盘不亮解决办法

    1.首先修改注册表打开[HKEY_USERS\.DEFAULT\Control Panel\Keyboard]项,将"InitialKeyboardIndicators"的键值从& ...