0

嗨,我想从网上获取一个代理列表并搜索它以找到有效的代理号码和端口。我的问题是当我抓取该网站时,我如何通过它进行搜索,它只识别 ips 和 poorts 并破坏其余部分?到目前为止我所做的一切都在工作,我如何只识别代理号码而不识别其他任何东西?很抱歉,任何帮助将不胜感激,但我是新手:)

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
4

1 回答 1

0

我建议使用正则表达式来查找 IP 地址和端口。这是一个需要的正则表达式:java regex 匹配 ip 地址和端口号作为捕获的组 本文解释了如何在 java 中使用正则表达式:http ://www.mkyong.com/regular-expressions/how-to-validate -ip-address-with-regular-expression/

于 2013-03-11T00:17:52.053 回答