commit afc87ea359f4ef143fbffb2ebe4f9192750be345
parent ac70b239e06be73985c506df4f8542840d4311ad
Author: Kebigon <git@kebigon.xyz>
Date: Fri, 13 Mar 2020 20:38:23 +0900
Handle price format "1744万5000円", fixes StringIndexOutOfBoundsException
Diffstat:
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/main/java/xyz/kebigon/housesearch/browser/suumo/SuumoBrowser.java b/src/main/java/xyz/kebigon/housesearch/browser/suumo/SuumoBrowser.java
@@ -43,8 +43,11 @@ public class SuumoBrowser extends Browser
final String url = posting.findElement(By.xpath("./div[@class='property_unit-header']/h2/a")).getAttribute("href");
final String priceField = getField(posting, "販売価格");
- final int priceSubstringIndex = priceField.indexOf("万円");
- final long price = Long.parseLong(priceField.substring(0, priceSubstringIndex)) * 10000;
+ final int tenthOfThousandsIndex = priceField.indexOf('万');
+ final int currencyIndex = priceField.indexOf('円', tenthOfThousandsIndex);
+ long price = Long.parseLong(priceField.substring(0, tenthOfThousandsIndex)) * 10000;
+ if (tenthOfThousandsIndex + 1 != currencyIndex)
+ price += Long.parseLong(priceField.substring(tenthOfThousandsIndex + 1, currencyIndex));
final String ageField = getField(posting, "築年月");
final int ageSubstringIndex = ageField.indexOf("年");