【发布时间】:2013-06-20 19:53:12
【问题描述】:
我在页面上有一篇文章,我需要解析所有文本。
我知道一篇文章超过 15 个字,用符号“”或“,”或“-”或“:”或“.”连接。
如何使用 Ruby 编写 Regexp 来分析页面上的文章并解析它?
我需要解析正文:ATLANTA — From the sublime emotional high provided by Matt Harvey and Zack Wheeler, the Mets’ young, hard-throwing right-handers, the team on Wednesday descended back to the realities of its everyday existence...
我知道如何解析和获取页面内容,但我不知道如何在 Regexp 上编写它! 要分析带有所需文本的父 HTML 标记,我必须编写一些正则表达式来检查规则: 文章超过 15 个字,仅使用符号“”或“,”或“-”或“:”或“.”连接。
【问题讨论】:
-
需要更多信息、示例字符串或输入以及预期输出。
-
Mechanize 带有 nokogiri。因此,您可以使用 mechanize 实例中的所有 nokogiri 方法。有很多教程和文档可以证明这一点。
-
在需要报废时使用 Nokogiri。