dqd3690
2015-03-03 16:22
浏览 51
已采纳

使用cURL和PHP从iTunes中检索RSS Feed

Been trying to get some PHP cURL code to work that gets the RSS feed from iTunes when you give it the podcast URL. Here is the code:

$inputString = "curl -A 'iTunes/12.1.1.4 (Windows; U; Microsoft Windows 7 Home Premium Edition Service Pack 1 (Build 7601) DPI/96' -s 'https://itunes.apple.com/podcast/id530114975'";  
$input = shell_exec($inputString);
$dom = new DOMDocument();
$html = $dom->loadHTML($input);

The cURL call when executed using shell_exec returns a blank string. When I call the loadHTML function it gives the following error, which is pretty obvious given the cURL call doesn't return anything.....

Warning: DOMDocument::loadHTML(): Empty string supplied as input in C:\php scripts\itunesFeedExtractor.php on line 130

Now, I got the PHP cURL code from somewhere else, haven't used it before, and tried to modify it to match my computers setup.... I've changed Windows version, service pack, build no. (Don't know why the DPI/96 is needed so I left it alone)

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doujiao4705 2015-03-04 22:15
    已采纳

    Well I got it working by adding to more curl_setopt() options. The full code now reads:

    $ch = curl_init("https://itunes.apple.com/podcast/id530114975");
    curl_setopt($ch, CURLOPT_USERAGENT, "iTunes/12.1.1.4 (Windows; U; Microsoft Windows 7 Home Premium Edition Service Pack 1 (Build 7601) DPI/96");
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    

    Cheers.....

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dtb81443 2015-03-03 16:51

    You'd be better off using the PHP curl extension:

    $ch = curl_init("https://itunes.apple.com/podcast/id530114975");
    curl_setopt($ch, CURLOPT_USERAGENT, "iTunes/12.1.1.4 (Windows; U; Microsoft Windows 7 Home Premium Edition Service Pack 1 (Build 7601) DPI/96");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    

    But if you really want to use the shell_exec method, make sure curl is in your path - you can check by running the curl command from cmd / a terminal

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题