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?
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]", "");
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?
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]", "");