dtnpf35197 2014-08-17 21:34
浏览 29

阅读使用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 :

Example Page

This table is racing game results. I didn't write the JS, and I can't change the format of the results. 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.

  • >>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.

Here is the JS : click Thank you !

  • 写回答

1条回答 默认 最新

  • dpnvrt3119 2014-08-17 21:56
    关注

    Here's how you'd be able to parse the initial array in 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. You might want to try to install NodeJS and make it parse the JS but might be an overkill. 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.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大