A
A
Andrey Dugin2015-07-27 20:51:23
HTML
Andrey Dugin, 2015-07-27 20:51:23

How to formulate a generic expression for XPath?

I'm trying to get the number of views from Avito. Found two options:
1) https://www.avito.ru/novocherkassk/sport_i_otdyh/x...

<div class="item-views">
    <!--noindex-->
    Просмотров: 
    <span class="js-show-stat pseudo-link" data-config="{ &quot;type&quot;: &quot;item&quot;, &quot;url&quot;: &quot;/items/stat/562148872&quot; }">всего&nbsp;121, сегодня&nbsp;23</span>
    <!--/noindex-->
</div>

The div has a span, the XPath looks like this:
//*[@id="item"]//div[@class="item-views"]/span/text()

2) https://www.avito.ru/rostov-na-donu/telefony/remes...
<div class="item-views">
    <!--noindex-->
    Просмотров: всего&nbsp;20, сегодня&nbsp;20
    <!--/noindex-->
</div>

The text goes directly to the div, but there is no span => XPath:
//*[@id="item"]//div[@class="item-views"]/text()
How to write a universal XPath that works in both cases?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Dugin, 2015-07-27
@adugin

It looks like this is how it works. Not sure if correct:
//*[@id="item"]//div[@class="item-views"]|/span

S
Sergey Gologuzov, 2015-07-27
@ser_gos

Hey!
Try like this:
Seems to be working...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question