douzhi1972 2016-12-30 05:38
浏览 71
已采纳

Php curl远程页面javascript提取

I have a remote page, below shows its source code,

<!DOCTYPE html>
<html>
<head>
    <title>somethingg blabla</title>
</head>
<body>
<script type="text/javascript">
    function blala( ) { /*** code **/ }
    var sitedata = {
            "count": 1,
            "threads": {
                "38752": {
                    "thread_id": 38752,
                    "node_id": 4,
                    "title": "The ShadyCraft Beta Launch!", 
                    "prefix_id": 19, 
                    "content": {
                        "count": 1,
                        "content": {
                            "226167": {
                                "post_id": 226167

                            }
                        }
                    }
                }
            }
        };
var extra_codes_here = 'blabla';
</script>

<h1>Hello world</h1>
</body>
</html>

I have code for curl this page and i got this source code, but how to get the value var sitedata to php array ,

  • 写回答

1条回答 默认 最新

  • doushun9875 2016-12-30 05:55
    关注
    $doc; // your document
    
    preg_match('/var\ssitedata\s=\s({.*});/s', $doc, $matches);
    $json = $matches[1];
    print_r(json_decode($json, true));
    

    and your json is incorrect.

    "post_id": 226167, 
    

    to

    "post_id": 226167
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献