doushi3803 2013-07-09 18:30
浏览 33
已采纳

使用PHP简单的HTML DOM Parser获取Vine视频网址和图像

So i like to take vine image url and video url using PHP Simple HTML DOM Parser.

http://simplehtmldom.sourceforge.net/

here is a example vine url

https://vine.co/v/bjHh0zHdgZT

So i need to take this info from the URL. Form image 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">

and For the video 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">

I want to take only the content of the these meta tags. if anyone can help really appreciate it. Thanks

  • 写回答

1条回答 默认 最新

  • dongyukui8330 2013-07-09 18:43
    关注

    Instead of using the lib you pointed out, I'm using native PHP DOM in this example, and it should work.

    Here's a small class I created for something like that:

    <?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;
      }
    
    }
    

    To use it you can try:

    $url = "https://vine.co/v/bjHh0zHdgZT";
    $dom = new DomFinder($url);
    $content_cell = $dom->find("//meta[@property='twitter:player:stream']", 'content');
    print $content_cell[0];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)