如何卷曲PHP SpeakerDeck.com Oembed URL



你能帮我卷曲PHP speakerdeck.com oembed URL 吗

我试过了,但它什么都不回。

<?php
$url='https://speakerdeck.com/oembed.json?url=http://www.speakerdeck.com/addyosmani/css-performance-tooling';
function get_data($url){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16");
        $curlData = curl_exec($curl);
        curl_close($curl);
        return $curlData;
    }

get_data($url);
?>

你的代码对我来说很好。也许你的问题应该更清楚。你是说你想抓取网页的内容吗?

如果你想获取http返回代码(你的代码),这是有效的:

$url='https://speakerdeck.com/oembed.json?url=http://www.speakerdeck.com/addyosmani/css-performance-tooling';
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, TRUE); 
curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
$head = curl_exec($ch); 
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
print_r($httpCode);
curl_close($ch);

如果你想要网页内容:

$url='https://speakerdeck.com/oembed.json?url=http://www.speakerdeck.com/addyosmani/css-performance-tooling';
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, TRUE); 
//curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
$page = curl_exec($ch); 
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
//you can do some error checking if you want here.
print_r($page);
curl_close($ch);

为您的新代码:

get_data($url);

尝试:

echo get_data($url);

相关内容

  • 没有找到相关文章

最新更新