刷csdn訪問量

    經過HttpURLConnection訪問。只需改一下博客地址就好了,而後後臺經過Jsoup解析博客的博客地址,而後經過多線程刷博客訪問量(線程數量可根據本身電腦配置進行適當的修改)。代碼(工程下載地址:http://pan.baidu.com/s/1hqEpdty)分爲三個部分 java

一、ListLinks.java:博客地址解析類。 node

二、VisitThread.java:多線程訪問類。 多線程

三、Main.java:主程序類。 app

1、ListLinks.java ide

package com.cxhd.visit;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Example program to list links from a URL.
 */
public class ListLinks {
    public static void main(String[] args) throws IOException {
        getVisitUrls("http://blog.csdn.net/lmj623565791?viewmode=contents");
    }
    public static List<String> getVisitUrls(String url){
        Document doc = null; 
        try {
            doc = Jsoup.connect(url).data("query", "Java") // 請求參數
                    .userAgent("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; BIDUBrowser 2.x)")
                    .timeout(3000000) // 設置鏈接超時時間
                    .post(); // 使用post方法訪問 URL
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        
        Elements links = doc.select("span").attr("class", "link_title").select("a");

        List<String> urls = new ArrayList<String>();
        for(int i=0; i<links.size()-1; i++){
            if(i%3==0){
                urls.add(links.get(i).attr("abs:href"));
                System.out.println(links.get(i).attr("abs:href"));
            }
        }
        return urls;
    }
}

2、VisitThread.java post

package com.cxhd.visit;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class VisitThread extends Thread {
        private String url;
	
	public VisitThread(String url){
		this.url = url;
	}
	
	public void run() {
		for(int i=1; i<=20000; i++){
			try {
				visit(url);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
//    private static Proxy proxy;
//    static {
//        SocketAddress sa = new InetSocketAddress("120.26.192.127", 3128);
//        proxy=new Proxy(java.net.Proxy.Type.HTTP, sa);  
//    }
    
    public void visit(String url) throws IOException {
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        connection.setRequestProperty("User-Agent", "");
        connection.getInputStream();
        connection.disconnect();
        
//        HttpURLConnection connection = (HttpURLConnection)new URL(url).openConnection(proxy);
//	      
//        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
//        connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36");
//        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
//        String s;
//        while ((s=reader.readLine())!= null){
//            System.out.println(s);
//        }
//        reader.close();
//        connection.disconnect();
    }
}

3、Main.java this

package com.cxhd.visit;

import java.util.List;

public class Main {

    public static void main(String[] args) {
        List<String> urls = ListLinks.getVisitUrls("http://blog.csdn.net/wangyongge85?viewmode=contents");
        for(int k=0; k<15; k++){// 43*10000*10
            for(String url:urls){
                new VisitThread("http://blog.csdn.net/zhangxin09/article/details/48209239").start();
            }
        }
    }
}
相關文章
相關標籤/搜索