2013-03-11 71 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