Php curl远程页面javascript提取

时间:2016-12-30 05:38:46

标签: javascript php curl

我有一个远程页面,下面显示了它的源代码,

<!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>

我有curl这个页面的代码,我得到了这个源代码,但是如何获得值var sitedata到php数组,

1 个答案:

答案 0 :(得分:1)

$doc; // your document

preg_match('/var\ssitedata\s=\s({.*});/s', $doc, $matches);
$json = $matches[1];
print_r(json_decode($json, true));

你的json不正确。

"post_id": 226167, 

"post_id": 226167