天天看點

ugg

import java.io.bufferedreader;

import java.io.bufferedwriter;

import java.io.file;

import java.io.filereader;

import java.io.filewriter;

import java.io.ioexception;

import java.io.inputstreamreader;

import java.net.httpurlconnection;

import java.net.socketexception;

import java.net.url;

import java.util.properties;

public class test2 {

public static void main(string[] args) {

// gethost("http://www.youdaili.net/daili/http/2572_4.html") ;

file f = null ;

bufferedreader br = null ;

filereader fr = null ;

string s = "" ;

string[] host = new string[2] ;

try {

f = new file("e:\\host.txt") ;

fr = new filereader(f) ;

br = new bufferedreader(fr) ;

s = br.readline() ;

while(s!=null) {

system.out.println("換一次ip" + s);

host = s.split(":") ;

//******************************

properties sys = system.getproperties();

sys.put("proxyset","true");

sys.put("proxyhost",host[0]);

sys.put("proxyport",host[1]);

system.setproperties(sys);

getdata() ;

}

} catch (exception e) {

system.out.println(e);

}finally {

if(br != null) {

br.close();

if(fr != null) {

fr.close();

} catch (ioexception e) {

e.printstacktrace();

public static void getdata() {

system.out.println("進入getdata");

url url ;

int responsecode ;

httpurlconnection httpurlconnection ;

string str = "" ;

stringbuffer sb = new stringbuffer() ;

inputstreamreader isr = null ;

for(int i=0;i<200;i++){

url = new url("http://www.uggaustralia.cn/thisisugg/api.php?ctrl=page&action=voteweibo&pid=4218") ;

httpurlconnection = (httpurlconnection)url.openconnection() ;

httpurlconnection.setconnecttimeout(5000);

httpurlconnection.setreadtimeout(5000);

httpurlconnection.setrequestproperty("user-agent","mozilla/5.0 (macintosh; intel mac os x 10_7_5) applewebkit/537.11 (khtml, like gecko) chrome/23.0.1271.64 safari/537.11") ;

responsecode = httpurlconnection.getresponsecode() ;

if(responsecode ==200){

isr = new inputstreamreader(httpurlconnection.getinputstream(),"gbk") ;

br = new bufferedreader(isr) ;

while((str=br.readline())!=null){

sb.append(str) ;

}else{

throw new socketexception() ;

system.out.println(sb.tostring());

if(sb.tostring().contains("\"data\":2")) {

break ;

sb = new stringbuffer() ;

if(isr != null) {

isr.close();

/**

* 獲得有代理網上的ip

*/

public static void gethost(string dailiurl) {

url = new url(dailiurl) ;

isr = new inputstreamreader(httpurlconnection.getinputstream(),"utf-8") ;

str = br.readline() ;

while(br.readline()!=null){

if(str.contains("@http#")){

str = str.replace("<p>", "").trim() ;

str = str.substring(0, str.indexof("@")) ;

str += "\r\n" ;

hostwritetofile(sb.tostring()) ;

* 把拿到的代理ip寫入檔案中

* @param str

public static void hostwritetofile(string str) {

filewriter fw = null ;

fw = new filewriter("e:\\host.txt",true) ;

fw.write(str);

fw.flush();

fw.close();