标题基于jsoup.connect爬ip代理 刷访客
这是从一个ip代理网址爬取大量ip,然后去刷需要访客的网址,
doc = Jsoup.connect("http://www.nimadaili.com/https/"+x)//该网址是要爬的代理的ip
.timeout(3000)
//.proxy("61.164.39.66",53281)*若注释掉此项,则是默认本机ip*
.ignoreHttpErrors(true)
//可不填
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0")
.get();
//System.out.println(doc);
这是获取html的标签
Elements elements=doc.select("tr");
Elements td=elements.select("td:eq(0)");
将爬取到的代理存到本地
Set<String> set1=ipmap.keySet();
Writer out=null;
try {
out=new FileWriter("D:/ip代理/ip.text",true);
for (String string : set1) {
out.write(string+":"+map.get(string));
out.write("\r\n");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
利用jdk自带的线程池,创建多线程来反复执行
static ExecutorService executorService=Executors.newFixedThreadPool(50);
Thread2 thread2=new Thread2();
executorService.execute(thread2);
Thread.sleep(5000);