使用cURL和phpQuery错误

时间:2012-11-10 14:28:32

标签: php phpquery

这是我的代码:

    <?php 

require('phpQuery.php');

function download($url)
{
    $curl = curl_init();
    curl_setopt_array($curl, array
    (
        CURLOPT_URL => $url,
        CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CONNECTTIMEOUT => 120,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HEADER => false
    ));

    $data = curl_exec($curl);
    curl_close($curl);

    return $data;
}

$pagina1 = phpQuery::newDocument(download('http://google.com'));

$logosrc = pq('img#hplogo').attr('src');
echo $logosrc;


?>

错误:

  

致命错误:在第26行的C:\ xampp \ htdocs \ projects \ new \ extract.php中调用未定义的函数attr()

谁知道问题出在哪里?

1 个答案:

答案 0 :(得分:1)

更改

$logosrc = pq('img#hplogo').attr('src');

$logosrc = pq('img#hplogo')->attr('src');

我想,但我没有测试过它。

Look here for more info