好的,我有这个页面,我想删除内容.. 但是统计数据是用 JavaScript 生成的。有什么办法可以获得统计数据吗?我尝试使用 PHP get_content thingy ...
这是我想要获取的页面中的示例。这<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 >
最佳答案
我想你的意思是你通过 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 ;
}
}
关于php - 从脚本标签中的网页抓取内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4770879/