我想在我的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/xyz/";
$dom = new domDocument();
$dom->loadHTML($result);
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('script type');
?>
我正在使用 DOM 从 HTML 获取内容:'script type'
以后,但无法获取它。
实际上应该调用 callInstagram($url)
函数,否则$result
变量将为空。因此,主例程应该这样开始(添加第二行):
$url = "https://www.instagram.com/ravij28/";
$result = callInstagram($url);
$dom = new DOMDocument();
$dom->loadHTML($result);
[..]
另外,当您要检索页面上的脚本时,您需要使用标签名称,该名称只是script
,而不是script type
。因此,代码段的最后一行需要阅读:
$tables = $dom->getElementsByTagName('script');