How can I only extract number from tags in Xpath?

Question:

hots = html.xpath('//*[@id="pl_top_realtimehot"]/table/tbody/tr/td[2]/span/text()')[1:]

The list I get from hots is including numbers and characters. How can I get numbers only in Xpath?

Asked By: XXXten6b

||

Answers:

You can not do that directly with XPath.
What you can do is to get the hots string and then to extract numbers from it.
You did not mention programming language you are using, so for example with Java you can do as following:

String numberOnly= hots.replaceAll("[^0-9]", "");

How to do that with Python please see here and here

Answered By: Prophet
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.