【问题标题】:Parsing Specific Portion of HTML Block解析 HTML 块的特定部分
【发布时间】:2018-05-24 23:23:09
【问题描述】:

我正在从一个看起来像这样的网站中提取一个 HTML 块

<strong>Suggested use:</strong> 
"This is the suggested use text"
<br><br>
<strong>Warning:</strong> 
"This is the warning text"

我正在尝试仅提取建议使用块下的文本和警告块下的文本的值,并将它们存储在 2 个单独的字段中。我很难弄清楚如何具体解析这个。有人有什么想法吗?

【问题讨论】:

  • 到目前为止你有没有尝试过?它是什么语言或工具?
  • 你能添加你的 html 文档的较大部分吗?我想查看您文档这部分的父节点

标签: php regex parsing


【解决方案1】:

我看到你将其标记为正则表达式:

$str  = '<strong>Suggested use:</strong> "This is the suggested us text" <br><br> <strong>Warning:</strong> "This is the warning text"';

if (preg_match_all('/"([^"]+)"/', $str, $m)) 
    print_r($m[0]);  

输出: Array ( [0] =&gt; "This is the suggested use text" [1] =&gt; "This is the warning text" )

另外,如果您不希望引号使用: print_r($m[1]);

编辑:我以为我在 PHP 部分所以假定它是 php 正则表达式,一些澄清会很棒。

【讨论】:

    猜你喜欢
    • 2020-09-23
    • 1970-01-01
    • 2013-06-08
    • 1970-01-01
    • 2011-08-04
    • 2018-05-20
    • 2010-12-28
    • 1970-01-01
    • 2015-02-11
    相关资源
    最近更新 更多