douxiong2738 2016-03-29 15:30
浏览 61

无法使用CURL获取Feed内容

I'm trying to get the content of this feed : http://www.institut-viavoice.com/viavoice-paris/publications/sondages-publies?format=feed&type=rss

Here is my code :

$url = 'http://www.institut-viavoice.com/viavoice-paris/publications/sondages-publies?format=feed&type=rss';

$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER         => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING       => "",
CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",
CURLOPT_AUTOREFERER    => true,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT        => 30,
CURLOPT_MAXREDIRS      => 10
);

$curl = curl_init($url); 
curl_setopt_array( $curl, $options ); 
$content = curl_exec($curl); 
curl_close($curl);

echo $content;

I tried many other CURL options but it doesn't work. As the content is accessible through my browser, I suppose it can be done with PHP. But what is wrong with my code ? It seems like there is an exception with the server of this feed ?

  • 写回答

1条回答 默认 最新

  • dongqiuxu2270 2016-03-29 15:42
    关注

    Not sure, may be your breaking the cURL options and calling the URL. Here a simple example, give it a try:

    function get_data($url) {
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0");
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
    
    $content = get_data('http://www.institut-viavoice.com/viavoice-paris/publications/sondages-publies?format=feed&type=rss');
    
    echo $content;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100