Tomasina
@Tomasina
Инженер-разработчик

Как победить XPath?

Вот фрагмент кода страницы:
<div class="s-price-wrapper">
<span class="s-price fs-4 fw-semibold text-dark me-2 js-product-price">
<span class="price-wrapper">
<span class="price">715
</span>
<span class="currency">
<span class="ruble">₽
</span>
</span>
</span>
</span>
<span class="s-compare-price fs-6 text-quaternary js-compare-price">
<span class="price-wrapper">
<span class="price">1 290
</span>
<span class="currency">
<span class="ruble">₽
</span>
</span>
</span>
</span>
</div>
</div>
<span class="sku-no-stock mt-2" style="display: none;">Нет в наличии
<div class="b-product-stocks s-stocks-wrapper">
<span class="stock-none d-flex align-items-center fs-sm text-quaternary">Нет в наличии
</span>
</span>
<span class="sku-not-available mt-2" style="display: none;">Товар с выбранным набором характеристик недоступен для покупки
<span class="stock-none d-flex align-items-center fs-sm text-quaternary">Нет в наличии
</span>
</span>
<div class="sku-3526-stock" data-sku-count="">
<span class="stock-high d-flex align-items-center fs-sm text-quaternary">
<i class="b-stock-icon bg-success me-1">В наличии: шт.
</span>
</div>
</div>
<div class="d-flex gap-2 mt-5">
<div class="b-product-quantity s-quantity-section" id="js-quantity-section">
<div class="input-group">
<button class="btn btn-theme btn-lg px-2 js-decrease js-min-description" type="button">
<span class="s-icon">-
</span>
</button>
<input type="text" class="form-control px-0 bg-theme text-center js-quantity-field" name="quantity" value="1">
<button class="btn btn-theme btn-lg px-2 js-increase js-max-description" type="button">
<span class="s-icon">+</span>
</button>
<div class="b-product-submit s-button-wrapper flex-grow-1">
<button class="btn btn-theme btn-lg w-100 js-submit-button" type="submit">
<span class="spinner-border spinner-border-sm d-none" role="status" aria-hidden="true">
</span>
<span class="spinner-text text-nowrap">В корзину
</span>
</button>
</div>
</div>
</div>
</div>
<div class="b-product-total s-prices-section ">
<div class="card border-0 bg-white-dark shadow">
<div class="card-body">
<div class="s-summary-wrapper">
<div class="fs-6">Итого:
</div>
<div class="s-summary-price js-product-total-price fs-2 fw-semibold">
<span class="price-wrapper">
<span class="price">715
</span>
<span class="currency">
<span class="ruble">₽
</span>
</span>
</span>
</div>
</div>
</div>
</div>
</div>

Выражение
=IMPORTXML($B$100;"//span[@class='price']")

выдает результат на три строки:
715
1290
715

Как выцепить только первое значение?
  • Вопрос задан
  • 204 просмотра
Решения вопроса 1
ProgrammerForever
@ProgrammerForever Куратор тега Excel
Учитель, автоэлектрик, программист, музыкант
=индекс(ваша_формула;1;1)
или
=chooserows(ваша_формула;1)
или сделать так:
( ваш_xpath )[1]
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы