RedVelvet
RedVelvet

Reputation: 1913

Take only a part of text from Xpath

Hello i have the following html code.

<div class="Clr-888 Fz-12 Lh-18">
   45 answers
   <span class="Fz-14">·</span>
     <a data-rapid_p="3" class="Clr-b" href="/dir/index/discover?sid=396545232" data-ylk="slk:cat;bpos:1;cpos:1;qid:20151010204849AAebNiK;sid:396545232">Baseball</a>
     <span class="Fz-14">·</span>
   1 day ago
 </div>

I need to take only the data field, in the second part of the div. (1 day ago). It's possibile to do only with xpath? Otherwise can you suggest me some easy regular expression in python to do this?

Upvotes: 0

Views: 68

Answers (1)

gbs
gbs

Reputation: 1325

Try this selector: /div/text()[last()]

Online demo here.

The only issue is that it will also include the leading whitespace but you can use something like Python's strip() to remove it afterwards.

Upvotes: 2

Related Questions