如何使用 PHP 简单 HTML dom 获取此文本?
How do I get this text using PHP Simple HTML dom?
假设我在 HTML 来源中有此 HTML 代码:
<div class="info">
<p><span class="strong">Score</span>4.32/5</p>
<p><span class="strong">Type</span>TV</p>
<p><span class="strong">Episodes</span>13</p>
<p><span class="strong">Status</span>Ongoing</p>
<p><span class="strong">Aired</span>Oct 3, 2015 - Dec 26, 2015</p>
<p><span class="strong">Age</span>PG-13 - Teens 13 or older</p>
</div>
如何使用 PHP 简单 HTML dom 从上面获取文本 4.32?
我试过了
foreach($info_html->find('.strong') as $library) {
$rating = $library->innertext;
var_dump($rating);
}
但这只给我文本 "score",但我想要 4.32。
也许这会给您想要的结果:
foreach($info_html->find('div.info p') as $library) {
$rating = $library->find('text', 1)->innertext;
var_dump($rating);
}
或者你可以先找到
标签元素:
foreach($info_html->find('p') as $library) {
$rating = $library->find('text', 1)->plaintext;
var_dump($rating);
}
假设我在 HTML 来源中有此 HTML 代码:
<div class="info">
<p><span class="strong">Score</span>4.32/5</p>
<p><span class="strong">Type</span>TV</p>
<p><span class="strong">Episodes</span>13</p>
<p><span class="strong">Status</span>Ongoing</p>
<p><span class="strong">Aired</span>Oct 3, 2015 - Dec 26, 2015</p>
<p><span class="strong">Age</span>PG-13 - Teens 13 or older</p>
</div>
如何使用 PHP 简单 HTML dom 从上面获取文本 4.32? 我试过了
foreach($info_html->find('.strong') as $library) {
$rating = $library->innertext;
var_dump($rating);
}
但这只给我文本 "score",但我想要 4.32。
也许这会给您想要的结果:
foreach($info_html->find('div.info p') as $library) {
$rating = $library->find('text', 1)->innertext;
var_dump($rating);
}
或者你可以先找到
标签元素:
foreach($info_html->find('p') as $library) {
$rating = $library->find('text', 1)->plaintext;
var_dump($rating);
}