【发布时间】:2021-07-06 23:30:22
【问题描述】:
我正在尝试在 PHP 中进行 Instagram 关注者计数。 (因为 JavaScript 不工作)
我得到了这个 PHP 脚本,但它不工作。
<?php
$url = 'https://www.instagram.com/cristiano/';
$str = file_get_contents($url);
$count = 0;
if(preg_match('#followed_by": {"count": (.*?)}#', $str, $match)) {
$count = $match[1];
} echo $count;
?>
【问题讨论】:
-
我认为是因为您的 preg_match 语句返回 false ,因此认为它永远不会更新。
-
你应该检查
$str的内容,因为php.net/manual/en/…可能被禁用了 -
另外,您正在下载的 HTML 中可能不存在该字符串。相反,它存在于由 JavaScript 生成的 DOM 中。
-
我认为
$str是一个HTML,但我对PHP不太了解。 -
离题:无法重现 / 需要调试细节 3v4l.org/Jtu8K 如果这不是关于
preg_match()调用,而是关于抓取url,然后删除问题中file_get_contents()行之后的所有内容。 stackoverflow.com/q/35234096/2943403 有什么对你有帮助的吗?