2013-03-11 73 views
0

您好,我想從網上抓取一個代理列表,並通過它找到工作代理號碼和端口。我的問題是,當我抓住網站如何通過它搜索它確定只是ips和poorts和disragrd休息?所有我到目前爲止doeint工作 我如何確定代理號碼,沒有別的?而遺憾的任何幫助,將不勝感激,但我對於新手:)在網站上發現ip?

package proxytester; 

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.net.MalformedURLException; 
import java.net.URL; 

public class ProxyTester{ 

    public static void main(String[] args) { 

try{ 
    URL grab = new URL("http://www.example.com"); 
    BufferedReader in = new BufferedReader(
    new InputStreamReader(grab.openStream())); 
    String input; 
    while ((input = in.readLine()) != null) { 
    if(input.charAt(0)=='n'){// the site starts its proxy list with name but this line throws an error 
     System.out.println(input); 
    }else if(input.charAt(0)== ' '){ 
     System.out.println("empty"); 
    }else 
     continue; 
    } 
    in.close();   
}catch(MalformedURLException aa){ 
    System.out.println("site error"); 
}catch (IOException e) { 
    System.out.println("io error"); 
} 



    }//end main 

}//end main 

回答

0

我會建議使用正則表達式查找IP地址和端口。這是需要一個正則表達式:java regex matching ip address and port number as captured groups 本文介紹瞭如何使用正則表達式在java中:http://www.mkyong.com/regular-expressions/how-to-validate-ip-address-with-regular-expression/

+0

感謝將看看 – user2155009 2013-03-11 00:26:02

+0

感謝配發我使用正則表達式 「\\ d {1,3} (?:\\ d {1,3}){3}(:: \\ d {1,5}?)「;? 它工作正常,如果代理服務器和端口是分開的,但如果他們是由標籤空間隔離然後我想 「\\ d {1,3}(?:\\。\\ d {1,3 }){3}(\\小號\\小號\\小號\\小號\\小號\\小號\\小號\\ d {1,5})「?; 但我只輸出代理不是端口任何建議將是偉大的,直到昨晚我didint甚至知道這個Java功能謝謝 – user2155009 2013-03-11 14:50:11

+0

有一個標籤空間序列「\\噸」。 – alu 2013-03-11 17:23:46