【问题标题】:Parse Website for Download Links?解析网站以获取下载链接?
【发布时间】:2012-03-06 15:55:04
【问题描述】:

我为我们的客户编写了一个小工具,可以从开发人员提供的永久链接中为我们的客户下载该软件的最新稳定版本。但是,他们的测试版和开发版确实有永久链接,因此每次都需要我手动更新代码。

是否有任何简单的方法可以解析此站点http://dl.bukkit.org/downloads/craftbukkit/ 以获取指向每种类型的最新下载 URL 的链接? (发布/测试版/开发版)?

【问题讨论】:

    标签: php html parsing xml-parsing


    【解决方案1】:

    看看这个 PHP Lib:http://simplehtmldom.sourceforge.net/ 它完全符合您的要求。

    【讨论】:

      【解决方案2】:
      require_once('simple_html_dom.php');
      
      $html = file_get_html('http://dl.bukkit.org/downloads/craftbukkit/');
      
      $dom = new DOMDocument;
      libxml_use_internal_errors(true);
      echo $dom->loadHTML($html) ? "success<br/>" : "failed<br/>";
      libxml_clear_errors();
      $dom->preserveWhiteSpace = true;
      
      
      foreach ($dom->getElementsByTagName('div') as $element){
          if($element->getAttribute('class') == "innerContent"){
              foreach ($element->getElementsByTagName('a') as $link) {
                  if( $link->getAttribute('class') == "tooltipd")
                  {
                      echo $link->getAttribute('href')."<br/>";
                  }
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-26
        相关资源
        最近更新 更多