2011-01-22 39 views
1

OK,我有這個頁面我想要得到的內容關閉..但是統計信息在JavaScript製成。有什麼方法可以得到統計數據嗎?我試圖使用PHP get_content啄...內容抓取網頁關閉是在腳本標記

這裏是在我想要得到的頁面的例子。 <script>位於<body>標記之間。

<script> 

na=0; 
S=new Array; 
S[na]="|Beal|3266561|137|131|1170664|714062|1378742|2375|128|322|"; na++; 
S[na]="|Marine|2446933|165554|125613|1116688|652869|187250|23773|27019|148167|"; na++; 
S[na]="|Krackle1|2306919|342794|440503|372482|238609|442226|146516|177399|146390|"; na++; 
S[na]="|LawyerUpSir|1666817|60579|236847|379476|219395|446057|149787|151306|23370|"; na++; 
S[na]="|IKillToWin|1657426|94695|214229|800157|446579|59618|9132|8861|24155|"; na++; 
S[na]="|Farts|1644623|6885|8790|972072|586678|49249|10558|2838|7553|"; na++; 

</script > 
+0

等待,所以你想獲得PHP的統計?如果JavaScript是內聯的,則它是文檔正文的一部分。 – 2011-01-22 22:08:20

回答

1

我希望你的意思是你必須通過遠程獲得它通過file_get_contents()頁的源代碼。然後,您只需使用正則表達式來匹配該源代碼中以S[na]開頭的所有行,然後在|上爆炸以使其以數組形式呈現。這應該會以可用的格式爲您提供數據。

$content = <<<END 
<script> 

na=0; 
S=new Array; 
S[na]="|Beal|3266561|137|131|1170664|714062|1378742|2375|128|322|"; na++; 
S[na]="|Marine|2446933|165554|125613|1116688|652869|187250|23773|27019|148167|"; na++; 
S[na]="|Krackle1|2306919|342794|440503|372482|238609|442226|146516|177399|146390|"; na++; 
S[na]="|LawyerUpSir|1666817|60579|236847|379476|219395|446057|149787|151306|23370|"; na++; 
S[na]="|IKillToWin|1657426|94695|214229|800157|446579|59618|9132|8861|24155|"; na++; 
S[na]="|Farts|1644623|6885|8790|972072|586678|49249|10558|2838|7553|"; na++; 

</script> 

...some HTML here.. 

END; 

$matches = array() ; 
preg_match_all("/S\[na\]\=\"\|(.*)\"\;\sna\+\+\;/", $content, $matches) ; 

$stats = array() ; 
if (count($matches) > 0 && is_array($matches[1])) { 
    foreach ($matches[1] as $match) { 
     $stats[] = $match ; 
    } 
}