尝试获取一些PHP cURL代码,以便在您为其提供播客URL时从iTunes获取RSS源。这是代码:
$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);
使用shell_exec执行时的cURL调用返回空字符串。 当我调用loadHTML函数时,它会给出以下错误,这很明显,因为cURL调用没有返回任何内容.....
Warning: DOMDocument::loadHTML(): Empty string supplied as input in C:\php scripts\itunesFeedExtractor.php on line 130
现在,我从其他地方获得了PHP cURL代码,之前没有使用它,并尝试修改它以匹配我的计算机设置....我已经更改了Windows版本,Service Pack,版本号。 (不知道为什么需要DPI / 96,所以我就把它留下了)
答案 0 :(得分:0)
最好使用PHP curl扩展程序:
$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);
但是如果你真的想使用shell_exec方法,请确保curl在你的路径中 - 你可以通过从cmd / a终端运行curl命令来检查
答案 1 :(得分:0)
我通过添加更多curl_setopt()选项来实现它。完整的代码现在是:
$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);
干杯.....