Java Brush CSDN Blog traffic Ideas

Source: Internet
Author: User

Let's take a look at the principle of CSDN statistics blog visits:

When a client initiates a request to the server, each IP is counted once, with three clients referring to three different IP addresses. And in a certain period of time, with the same IP access to the same article, can only be regarded as a single visit. The same IP within a certain time period to access the same blog different articles, the number of articles accessed +1. After knowing the simple principle of appeal, the next step is to solve it.

First, prepare a large number of IP proxies. 100 degrees, ho out a lot of ah, this is a lot of Lei Feng, I chose this IP proxy website, and provide the API call interface, the call address is:

Http://www.xicidaili.com/api.

Secondly, we need to introduce the jar package, here only need a jsoup package, do not be jsoup this noun scare, below I will post my blog, tell me what this buddy do.

    1. Jsoup-1.8.1.jar

Next write a wrapper IP class Java bean, actually do not write beans can also, directly placed in the string[] array is OK, but in doing so, the agent when the call is convenient to take out.

public class MyIp {    private String address;        Private String port;    Public String getaddress () {        return address;    }    public void setaddress (String address) {        this.address = address;    }    Public String Getport () {        return port;    }    public void Setport (String port) {        this.port = port;    }}

Now the main use of the tool to call this interface is: Jsoup, this buddy I recommend to see my blog http://blog.csdn.net/zhang5476499/article/details/52205150. Of course, you can also use httpclient and other tools to take down the contents of the page. The following are implemented in Java code:

public static list<myip> getip (String url) {list<myip> iplist = null; try {//1. Initiate a GET request to the IP proxy address and get the IP Document doc = jsoup.connect (URL) of the proxy. useragent ("Mozilla"                        ). Cookie ("auth", "token"). Timeout. get ();                        2, the resulting IP address is parsed except for string ipstr = Doc.body (). Text (). Trim (). toString ();                        3. Use regular expressions to cut all IP string[] ips = Ipstr.split ("\\s+");            4. Loop through the resulting IP string, encapsulated as MyIp bean IPList = new arraylist<myip> ();                For (final String ip:ips) {MyIp MyIp = new MyIp ();                string[] temp = Ip.split (":");                Myip.setaddress (Temp[0].trim ());                Myip.setport (Temp[1].trim ());            Iplist.add (MYIP);        }} catch (IOException e) {System.out.println ("Load document is coarse");    } return iplist; }

It is important to note that when the API calls this page, it uses a GET request. Well, assuming that the API has been given to the 100 proxy IP, then, we can set up the agent, the main code to set up the agent is as follows:

System.setproperty ("Http.maxredirects", "50"); System.getproperties (). SetProperty ("Proxyset", "true"); System.getproperties (). SetProperty ("Http.proxyhost", myip.getaddress ()); System.getproperties (). SetProperty ("Http.proxyport", Myip.getport ());

The next step is to recycle these received proxy IPs, each setting up an agent and sending a request to the blog address.

1  Public Static voidMain (string[] args) {2         //1. Want the HTTP proxy address API to initiate a request to obtain the desired proxy IP address3String url = "Http://api.xicidaili.com/free2016.txt";4List<myip> IPList =getip (URL);5String Blogurl = "";6Scanner sc =NewScanner (system.in);7         8System.out.print ("Please enter the article address:");9Blogurl =sc.nextline ();TenSystem.out.print ("Please enter a multiple of turns refresh (x100):"); One         intTime =sc.nextint (); A         intCount = 0; -          -          for(inti = 0; i< time; i++) { the             //2. Set up IP proxy -              for(FinalMyIp myip:iplist) { -System.setproperty ("Http.maxredirects", "50"); -System.getproperties (). SetProperty ("Proxyset", "true"); +System.getproperties (). SetProperty ("Http.proxyhost", Myip.getaddress ()); -System.getproperties (). SetProperty ("Http.proxyport", Myip.getport ()); +                  A                 Try { atDocument doc =Jsoup.connect (Blogurl) -. useragent ("Mozilla") -. Cookie ("auth", "token") -. Timeout (3000) - . get (); -                     if(Doc! =NULL) { incount++; -Logger.info ("Number of successful refreshes:" +count); to                     } +}Catch(IOException e) { -Logger.error (myip.getaddress () + ":" + myip.getport () + "error"); the                 } *             } $         }Panax Notoginseng}
Agent write to this almost end, in fact, brush flow does not need more advanced technology, this article is just a primer, hope to be able to pray for the role. Related code address: http://download.csdn.net/detail/zhang5476499/9687448--2016.11.27 14:08:30

Java Brush CSDN Blog traffic Ideas

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.