【问题标题】:Parsing JSON variables on Instagram在 Instagram 上解析 JSON 变量
【发布时间】:2014-04-28 14:54:41
【问题描述】:

我正在尝试从 Instagram 页面获取所有 JSON 变量和值

IE:查看源代码:http://instagram.com/justinbieber

你们有什么推荐的功能吗?

我尝试使用 json_decode 但并非所有页面都是 json - 它只会为我返回 null

【问题讨论】:

标签: json instagram


【解决方案1】:
$instagram_url="http://instagram.com/justinbieber";

$html = file_get_contents($instagram_url)
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$js = $xpath->query('//body/script')->item(1)->nodeValue;
$start = strpos($js, '{');
$end = strrpos($js, ';');
$json = substr($js, $start, $end - $start);

var_dump ($json);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多