0

だから私は、PHP Simple HTML DOM Parser を使用してつる画像の URL とビデオの URL を取得するのが好きです。

http://simplehtmldom.sourceforge.net/

ここにブドウのURLの例があります

https://vine.co/v/bjHh0zHdgZT

したがって、この情報を URL から取得する必要があります。フォーム画像の URL:

<meta property="twitter:image" content="https://v.cdn.vine.co/v/thumbs/8B474922-0D0E-49AD-B237-6ED46CE85E8A-118-000000FFCD48A9C5_1.0.6.mp4.jpg?versionId=mpa1lJy2aylTIEljLGX63RFgpSR5KYNg">

およびビデオの URL の場合

<meta property="twitter:player:stream" content="https://v.cdn.vine.co/v/videos/8B474922-0D0E-49AD-B237-6ED46CE85E8A-118-000000FFCD48A9C5_1.0.6.mp4?versionId=ul2ljhBV28TB1dUvAWKgc6VH0fmv8QCP">

これらのメタ タグのコンテンツのみを取得したい。誰かが本当に感謝するのを助けることができれば. ありがとう

4

1 に答える 1

1

あなたが指摘したライブラリを使用する代わりに、この例ではネイティブ PHP DOM を使用していますが、動作するはずです。

これは私がそのようなもののために作成した小さなクラスです:

<?php

class DomFinder {
  function __construct($page) {
    $html = @file_get_contents($page);
    $doc = new DOMDocument();
    $this->xpath = null;
    if ($html) {
      $doc->preserveWhiteSpace = true;
      $doc->resolveExternals = true;
      @$doc->loadHTML($html);
      $this->xpath = new DOMXPath($doc);
      $this->xpath->registerNamespace("html", "http://www.w3.org/1999/xhtml");
    }
  }

  function find($criteria = NULL, $getAttr = FALSE) {
    if ($criteria && $this->xpath) {
      $entries = $this->xpath->query($criteria);
      $results = array();
      foreach ($entries as $entry) {
        if (!$getAttr) {
          $results[] = $entry->nodeValue;
        } else {
          $results[] = $entry->getAttribute($getAttr);
        }
      }
      return $results;
    }
    return NULL;
  }

  function count($criteria = NULL) {
    $items = 0;
    if ($criteria && $this->xpath) {
      $entries = $this->xpath->query($criteria);
      foreach ($entries as $entry) {
        $items++;
      }
    }
    return $items;
  }

}

それを使用するには、次を試すことができます。

$url = "https://vine.co/v/bjHh0zHdgZT";
$dom = new DomFinder($url);
$content_cell = $dom->find("//meta[@property='twitter:player:stream']", 'content');
print $content_cell[0];
于 2013-07-09T18:43:01.720 に答える