使用url参数中的$ _GET在getAttribute()中使用

时间:2018-04-20 17:29:45

标签: php

所以我真的很困惑,因为我不断收到一个错误,说它是一个非对象,但我不确定我是否应该以某种方式将它转换为一个对象。这是我到目前为止所做的事情。

<?php
ini_set("allow_url_fopen", 1);

$url1 = $_GET['grab'];



function file_get_contents_curl($url){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            $data = curl_exec($ch);
            curl_close($ch);
            return $data;
}



    $str = $url1;
    $html = file_get_contents_curl($str);
        $doc = new DOMDocument();
        libxml_use_internal_errors(true);
        $doc->loadHTML('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . $html);
        libxml_clear_errors();

$nodes = $doc->getElementsByTagName('title')->item(0)->nodeValue;
        $hrefValue = $doc->getElementById('uc-download-link')->getAttribute("href"); 

echo $hrefValue;

1 个答案:

答案 0 :(得分:0)

好吧所以不要张贴整个网址而只是把ID作为重要的公园,然后重新组装脚本中的网址

<?php
ini_set("allow_url_fopen", 1);

$url1 = $_GET['id'];
$url2 = 'https://docs.google.com/uc?export=download&id=' . $url1;


function file_get_contents_curl($url){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            $data = curl_exec($ch);
            curl_close($ch);
            return $data;
}



    $str = $url2;
    $html = file_get_contents_curl($str);
        $doc = new DOMDocument();
        libxml_use_internal_errors(true);
        $doc->loadHTML('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . $html);
        libxml_clear_errors();

$nodes = $doc->getElementsByTagName('title')->item(0)->nodeValue;
        $hrefValue = $doc->getElementById('uc-download-link')->getAttribute("href"); 

echo $hrefValue;