Skip to content

Commit 0e7e40b

Browse files
committed
fix(series import): ignore text from children elements during price extraction.
1 parent ebc2acf commit 0e7e40b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/main/java/ru/mystamps/web/feature/series/importing/extractor/JsoupSiteParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,12 @@ protected String extractSellerUrl(Element body) {
309309
}
310310

311311
protected String extractPrice(Element body) {
312-
String price = getTextOfTheFirstElement(body, priceLocator);
313-
if (price == null) {
312+
Element elem = getFirstElement(body, priceLocator);
313+
if (elem == null) {
314314
return null;
315315
}
316316

317+
String price = elem.ownText();
317318
LOG.debug("Extracted price: '{}'", price);
318319
return price;
319320
}

src/test/java/ru/mystamps/web/feature/series/importing/extractor/JsoupSiteParserTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,23 @@ public void extractPriceShouldReturnTextOfPriceLocator() {
865865
assertThat(msg, price, equalTo(expectedValue));
866866
}
867867

868+
@Test
869+
public void extractPriceShouldIgnoreTextOfChildrenTags() {
870+
parser.setPriceLocator("#price");
871+
872+
String expectedValue = String.valueOf(Random.price());
873+
String html = String.format(
874+
"<span id='price'>%s<span class='currency'>RUB</span</span>",
875+
expectedValue
876+
);
877+
Element doc = createDocumentFromText(html);
878+
879+
String price = parser.extractPrice(doc);
880+
881+
String msg = String.format("couldn't extract price from '%s'", doc);
882+
assertThat(msg, price, equalTo(expectedValue));
883+
}
884+
868885
//
869886
// Tests for extractCurrency()
870887
//

0 commit comments

Comments
 (0)