package com.zxy.request;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class findIpProxy {
public String findNewIpProxyContent(String addr, Integer port, Integer i) {
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
HttpHost httpHost = null;
if (addr != null && port != null) {
httpHost = new HttpHost(addr, port);
System.out.println("本次请求的IP为:" + addr+":"+port);
}
HttpGet httpGet = new HttpGet("http://www.xicidaili.com/nn/" + i + "");
if (addr != null && port != null) {
RequestConfig config = RequestConfig.custom().setProxy(httpHost)
.setConnectTimeout(5000).setSocketTimeout(5000).build();
httpGet.setConfig(config);
}
httpGet.setHeader("Accept",
"text/html,application/xhtml+xml,application/xml;"
+ "q=0.9,image/webp,*/*;q=0.8");
httpGet.setHeader("Accept-Encoding", "gzip, deflate, sdch");
httpGet.setHeader("Accept-Language", "zh-CN,zh;q=0.8");
httpGet.setHeader("Cache-Control", "no-cache");
httpGet.setHeader("Connection", "keep-alive");
httpGet.setHeader("Host", "www.xicidaili.com");
httpGet.setHeader("Pragma", "no-cache");
httpGet.setHeader("Upgrade-Insecure-Requests", "1");
httpGet.setHeader(
"User-Agent",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
+ "(KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
try {
String responseContent;
HttpResponse httpResponse = closeableHttpClient.execute(httpGet);
responseContent = EntityUtils.toString(httpResponse.getEntity(),
"utf-8");
if (closeableHttpClient != null) {
closeableHttpClient.close();
}
return responseContent;
} catch (Exception e) {
System.out.println("本轮网页返回为空,有废弃ip");
}
return null;
}
public String findNewIpProxy_QuickDLContent(String addr, Integer port, Integer i) {
CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
HttpHost httpHost = null;
if (addr != null && port != null ) {
httpHost = new HttpHost(addr, port);
System.out.println("本次请求的IP为:" + addr+":"+port);
}
HttpGet httpGet = new HttpGet("http://www.kuaidaili.com/free/inha/" + i + "");
if (addr != null && port != null) {
RequestConfig config = RequestConfig.custom().setProxy(httpHost)
.setConnectTimeout(5000).setSocketTimeout(5000).build();
httpGet.setConfig(config);
}
httpGet.setHeader("Accept",
"text/html,application/xhtml+xml,application/xml;"
+ "q=0.9,image/webp,*/*;q=0.8");
httpGet.setHeader("Accept-Encoding", "gzip, deflate, sdch");
httpGet.setHeader("Accept-Language", "zh-CN,zh;q=0.8");
httpGet.setHeader("Cache-Control", "no-cache");
httpGet.setHeader("Connection", "keep-alive");
httpGet.setHeader("Host", "www.kuaidaili.com");
httpGet.setHeader("Referer", "http://www.kuaidaili.com/free/inha/"+i+"/");
httpGet.setHeader("Pragma", "no-cache");
httpGet.setHeader("Upgrade-Insecure-Requests", "1");
httpGet.setHeader(
"User-Agent",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
+ "(KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
try {
String responseContent;
HttpResponse httpResponse = closeableHttpClient.execute(httpGet);
responseContent = EntityUtils.toString(httpResponse.getEntity(),
"utf-8");
if (closeableHttpClient != null) {
closeableHttpClient.close();
}
return responseContent;
} catch (Exception e) {
System.err.println("本轮网页返回为空,有废弃ip");
}
return null;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
java多线程代理IP池
共32个文件
class:14个
java:12个
prefs:3个
需积分: 48 49 下载量 193 浏览量
2017-11-30
09:35:46
上传
评论 4
收藏 28KB RAR 举报
温馨提示
多线程代理IP池,一直看到有关这方面的技术,最近实现了一个。简单的来说,启动后,会一直定时的获取代理ip,并自动检测代理ip的活跃度。运用多线程的技术,在极短的时间内获取大量的ip进行筛选。架构也比较清楚,方便大家学习参考 需要主要的是,代理ip获取成功后是放在redis里面的,有关redis的参数配置在baseDB里面配置。当然对于没有开redis,我也进行处理放在了static里面。难者不会会者不难-=-。
资源推荐
资源详情
资源评论
收起资源包目录
IPProxyPool.rar (32个子文件)
IPProxyPool
src
main
java
com
zxy
entity
ipMessage.java 682B
start
open.java 764B
filter
IpActiveFilter.java 3KB
tools
IpProxyxicithread.java 1KB
IpProxyTools.java 1KB
IpProxyQuickDLthread.java 1KB
dataBase
redisDB.java 2KB
arrayDB.java 1KB
baseDB.java 726B
htmlParse
htmlParseCore.java 2KB
request
findIpProxy.java 4KB
test
java
com
zxy
IPProxyPool
AppTest.java 609B
.classpath 1022B
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.core.resources.prefs 119B
org.eclipse.jdt.core.prefs 243B
pom.xml 1KB
target
classes
com
zxy
entity
ipMessage.class 1KB
start
open$2.class 724B
open$1.class 706B
open.class 1KB
filter
IpActiveFilter.class 4KB
tools
IpProxyxicithread.class 2KB
IpProxyQuickDLthread.class 2KB
IpProxyTools.class 2KB
dataBase
redisDB.class 3KB
arrayDB.class 2KB
baseDB.class 1KB
htmlParse
htmlParseCore.class 3KB
request
findIpProxy.class 4KB
test-classes
com
zxy
IPProxyPool
AppTest.class 976B
.project 563B
共 32 条
- 1
资源评论
XyGoodCode
- 粉丝: 27
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功