我想要不。通过刮Instagram的粉丝。 使用以下代码:
<?php
function callInstagram($url)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$url = "https://www.instagram.com/ravij28/";
$dom = new domDocument();
$dom->loadHTML($result);
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('script type');
?>
错误:
解析错误:语法错误,意外&#39; $ dom&#39; (T_VARIABLE)在第20行的C:\ wamp \ www \ Trial \ curl.php
请提出一些解决方案。
答案 0 :(得分:3)
function callInstagram($url)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$url = "https://www.instagram.com/ravij28/";
$dom = new domDocument();
$dom->loadHTML(callInstagram($url));
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('script');
print_r($tables);
这显示DOMNodeList对象([length] =&gt; 11)AND
$tables = $dom->getElementsByTagName('script type');
print_r($tables);
显示 DOMNodeList对象([length] =&gt; 0)