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,以此类推.. ...
随机推荐
- IJKMediaFramework第三方库的使用
大多数做直播的时候使用 FFMpeg. IJKMediaFramework也是基于FFMpeg封装 使用起来比较简单,个人觉得如果有能力可以使用 FFMpeg , 使用 FFMpeg对 内存的占用比 ...
- HTML+CSS实例——漂亮的查询部件(一)
一.参考网址:www.kuhnsjewelers.com 二.效果: 三.HTML <div id="search-box"> <asp:TextBox ID=& ...
- [改善Java代码]不推荐覆写start方法
多线程比较简单的方式是继承Thread类,然后覆写run()方法,在客户端程序中通过调用对象的start方法即可启动一个线程,这个是多线程程序的标准写法. 错误代码: public class Cli ...
- 自己改写的asp.net MVC EF Respoistory 仓储模式
之前改写网上收集的Respoistory 模式感觉很多地方都是不可取的,这里经过这段时间的充电重新改写一版,当然注释已加,还有不懂的,可以留言我. 首先还是拿出IRespoistory的接口层代码 u ...
- 【AngularJs】---表单验证
1. 必填项 验证某个表单输入是否已填写,只要在输入字段元素上添加HTML5标记required即可: <input type="text" required /> 2 ...
- Genymotion安卓模拟器,性能最好
老笔记本用AndroidSDK自带的模拟器 启动慢 运行卡 用了Genymotion启动快,运行响应媲美真机 想起学生时代,那时候智能手机还未完全普及 也用模拟器玩过”电脑里的手机“.
- JDBC之数据连接
:数据库语句: create database LandDB; use LandDB; create table T_BL_CANTON_CODE ( CTN_CODE int primary key ...
- SQLSERVER2012数据库还原
(1)还原已存在数据库 还原时提示失败,因为数据库正在使用,无法获得独占访问权.解决办法,先分离已存在的数据库,再执行还原操作. 确定后居然成功了,因为我是先使用(2)还原数据库后直接尝试(1)方法还 ...
- 基于Tengine的反向代理详细配置
系统环境: SUSE Linux Enterprise Server 10 SP1 (x86_64) 注:所有软件包都放置在/data/software目录下 nginx_tcp_proxy_modu ...
- OC第一天-Xcode、工程组成及运行状态
Xcode 中iOS工程模版: 1.Application类型: Master-detail Application. 可以构建树形结构导航模式应用,生成的代码中包含了导航控制器和表示图控制器.(表示 ...