简体   繁体   English

阅读使用JavaScript生成的页面

[英]Read a page generated with JavaScript

this time I'm looking for something really special. 这次我正在寻找一些特别的东西。 In my PHP page, I got a table generated by a Javascript, here is the example : 在我的PHP页面中,我得到了一个由Javascript生成的表,这是示例:

Example Page 示例页面

This table is racing game results. 该表是赛车游戏的结果。 I didn't write the JS, and I can't change the format of the results. 我没有编写JS,也无法更改结果的格式。 What I need is to parse these results to get variables, to generate championship results giving points to guys, adding points of multiple series, etc... 我需要解析这些结果以获取变量,生成冠军成绩,为男生提供积分,添加多个系列的积分等...

I tried : 我试过了 :

  • Parsing with DOMDocument, also substr, but as it's JS generated it can't work. 使用DOMDocument进行解析,也可以使用substr,但是由于它是JS生成的,因此无法正常工作。

  • >>this solution<< which sounded good but it doesn't work. >>此解决方案<<听起来不错,但不起作用。

Do you guys have any idea to get an exploitable array ? 你们有什么想法得到可利用的阵列吗? If not, what do you suggest as alternative solution ? 如果没有,您对替代方案有何建议? I'm not able to reproduce the JS in a PHP function, too hard. 我无法用PHP函数重现JS,太难了。

Here is the JS : click Thank you ! 这是JS: 单击“谢谢”!

Here's how you'd be able to parse the initial array in PHP: 这是您如何解析PHP中的初始数组的方法:

$url = 'http://mxs-concept.com/liveresults/test.php';
$page = file_get_contents($url); // fetch the page

preg_match('/resultslines=(.+)print_race_analysis/sim', $page, $matches); // find javascript array
$js = preg_replace('/,\s+\]$/', ']', $matches[1]); // fix last comma before "]"

$array = json_decode($js); // decode the array
var_dump($array); // see the exact array you had in javascript

However, after reading your edit, it seems that you'd need more work if you're taking the PHP way. 但是,阅读完您的编辑后,如果您采用PHP方式,则似乎需要做更多的工作。 You might want to try to install NodeJS and make it parse the JS but might be an overkill. 您可能想尝试安装NodeJS并使其解析JS,但可能会显得过分。 If I would you, I'd translate the JS to PHP even if it will take a day just because NodeJS might take a week instead. 如果您愿意的话,即使Node.js可能要花一周的时间,我也会将JS转换为PHP,即使需要一天的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM