简体   繁体   English

我怎样才能只从 Xpath 中的标签中提取数字?

[英]How can I only extract number from tags in Xpath?

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?我怎样才能只在 Xpath 中获取号码?

You can not do that directly with XPath.您不能直接使用 XPath 执行此操作。
What you can do is to get the hots string and then to extract numbers from it.您可以做的是获取hots字符串,然后从中提取数字。
You did not mention programming language you are using, so for example with Java you can do as following:您没有提到您正在使用的编程语言,因此例如使用 Java 您可以执行以下操作:

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

How to do that with Python please see here and here如何使用 Python 做到这一点,请参阅此处此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM