0

URL から「zpid」を取得する必要があります。たとえば、次のリンクを参照して ください。 158.027859_rect/12_zm/

値 110560800 を取得する必要があります

URL パーサーhttps://docs.oracle.com/javase/tutorial/networking/urls/urlInfo.htmlを見つけまし たが、「zpid」を取得する方法が見つかりませんでした

4

2 に答える 2

0

必要なグループに一致する正規表現を記述する必要があります。あなたの場合、使用zpidする番号と一致する番号です\d+

private static String extract(String url) { // http://www.zillow.com/homes/for_sale/Laie-HI/110560800_zpid/18901_rid/pricea_sort/21.70624,-157.843323,21.565342,-158.027859_rect/12_zm/
    Pattern pattern = Pattern.compile("(\\d+)_zpid");
    Matcher matcher = pattern.matcher(url);
    while (matcher.find()) {
        return matcher.group(1); //110560800
    }
    return null;
}

Stringを使用して、これを数値にキャストできますInteger.parseInt

于 2016-10-26T03:25:29.110 に答える
0

方法は次のとおりです。

String s = "http://www.zillow.com/homes/for_sale/Laie-HI/110560800_zpid/18901_rid/pricea_sort/21.70624,-157.843323,21.565342,-158.027859_rect/12_zm/";

        String[] url = s.split("/");//separating the string with delimeter "/" in url

        for(int i=0;i<url.length;i++){
            if(url[i].contains("zpid")){//go through each slit strings and search for keyword zpid
                String[] zpid = url[i].split("_");//if zpid is found, get the number part
                System.out.println(zpid[0]);

            }
        }
于 2016-10-26T03:25:58.957 に答える