正则表达式在网页中查找值 [英] Regular expression to find a value in a webpage

查看:127
本文介绍了正则表达式在网页中查找值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



表格单元格的示例内容是结果:40分钟。



我需要一个正则表达式来匹配实际的数字(40)。

这是java,在此先感谢。

解决方案

之前我试过用正则表达式来做这件事,洞。



使用类似XPath表达式的东西要容易得多,您可以通过它在DOM层次结构中的位置来指定位置。 Apache库可以做到这一点(特别是Xalan),可以在这里找到: http://xml.apache .org / xalan-j /

您可以使用Firefox插件XPath Checker来帮助您解决这个问题。



如果您正在寻找其他工具/信息,您所谈论的区域称为网页抓取。


I need to find a regular expression which pulls out a value from a table cell in a html doc.

Example contents of this table cell are "Result: 40 mins".

I need a regular expression to match the actual number (40).

This is in java, thanks in advance.

解决方案

I've tried to do this with regular expressions before, and it is a pain in the hole.

It is MUCH easier to use something like an XPath expression, where you can specify the location by its place in the DOM hierarchy. The Apache libraries can do this (specifically Xalan) wihich can be found here: http://xml.apache.org/xalan-j/

You can use the Firefox addon XPath Checker to help you out with this.

The area you're talking about is called "web scraping" by the way, if you're looking for other tools/information.

这篇关于正则表达式在网页中查找值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆