我已经阅读并尝试了有关此问题的所有POST,但无法使其正常工作。这是HTML:
<meta itemprop="interactionCount" content="UserPlays:4635">
<meta itemprop="interactionCount" content="UserLikes:4">
<meta itemprop="interactionCount" content="UserComments:0">
我需要提取“ 4635”位。
码:
<?php
$html = file_get_html($url);
foreach($html->find("meta[name=interactionCount]")->getAttribute('content') as $element) {
$val = $element->innertext;
echo '<br>Value is: '.$val;
}
我什么也没回来?
$metaData= '<meta itemprop="interactionCount" content="UserPlays:4635">
<meta itemprop="interactionCount" content="UserLikes:4">
<meta itemprop="interactionCount" content="UserComments:0">';
$dom = new DOMDocument();
$dom->loadHtml($metaData);
$metas = $dom->getElementsByTagName('meta');
foreach($metas as $el) {
list($user_param,$value) = explode(':',$el->getAttribute('content'));
// here check what you need
print $user_param.' '.$value.'<br/>';
}
// OUTPUT
UserPlays 4635
UserLikes 4
UserComments 0
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句