douzhi1972
2016-12-30 05:38
浏览 65

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 ,

图片转代码服务由CSDN问答提供 功能建议

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

 <  code>&lt;!DOCTYPE html&gt; 
&lt; html&gt; 
&lt; head&gt; 
&lt; title&gt; somethingg blabla&lt; / title&gt; 
&lt; / head&gt; 
&lt; body&gt; 
&lt; script type =“text /  javascript“&gt; 
 function blala(){/ *** code ** /} 
 var sitedata = {
”count“:1,
”threads“:{
”38752“:{
  “thread_id”:38752,
“node_id”:4,
“title”:“ShadyCraft Beta Launch!”,
“prefix_id”:19,
“内容”:{
“count”:1  ,
“content”:{
“226167”:{
“post_id”:226167 
 
} 
} 
} 
} 
} 
} 
}; 
var extra_codes_here ='blabla'  ; 
&LT; /脚本&GT; 
 
&LT; H1&GT;  Hello world&lt; / h1&gt; 
&lt; / body&gt; 
&lt; / html&gt; 
   
 
 

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

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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
    
    打赏 评论

相关推荐 更多相似问题