繁体   English   中英

使用PHP simple_html_dom.php提取META

[英]Extracting META using PHP simple_html_dom.php

我已经阅读并尝试了有关此问题的所有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
include 'simple_html_dom.php';
$url = '...';
$html = file_get_html($url);
foreach ($html->find('meta[itemprop="interactionCount"]') as $element) {
    list($key, $value) = explode(':', strval($key->content));
    echo 'Value:'.$value."\n";
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM