我正在尝试做一个简单的提取,但我总是得到不可预测的结果。
我有这个 HTML 代码
<div class="thread" style="margin-bottom:25px;">
<div class="message">
<span class="profile">Suzy Creamcheese</span>
<span class="time">December 22, 2010 at 11:10 pm</span>
<div class="msgbody">
<div class="subject">New digs</div>
Hello thank you for trying our soap. <BR> Jim.
</div>
</div>
<div class="message reply">
<span class="profile">Lars Jörgenmeier</span>
<span class="time">December 22, 2010 at 11:45 pm</span>
<div class="msgbody">
I never sold you any soap.
</div>
</div>
</div>
而且我正在尝试从“msgbody”中提取外部文本,但前提是“profile”等于某个值。像这样。
$contents = $html->find('.msgbody');
$elements = $html->find('.profile');
$length = sizeof($contents);
while($x != sizeof($elements)) {
$var = $elements[$x]->outertext;
//If profile = the right name
if ($var = $name) {
$text = $contents[$x]->outertext;
echo $text;
}
$x++;
}
我从错误的配置文件中获取文本,而不是那些具有我需要的关联的配置文件。有没有办法只用一行代码提取所需的信息?
就像如果 span-profile = "correct name" 然后拉它的 div-msgbody