dongxing7083 2014-06-15 05:10
浏览 6

如何在PHP中刮取JavaScript值

I’m new to PHP and coding in general and I can’t figure this out. I’m trying to get the number of kills from this profile page.

At the moment, the string I am trying to get is:

29362

When I view the page source, this number is nowhere to be seen.

When I use inspect element, however, I find:

<td class="num">29362</td>

How can I get the content shown in inspect element instead of the content shown by viewing the page source?

  • 写回答

3条回答 默认 最新

  • duanlvji4780 2014-06-15 05:20
    关注

    In using a tool like Firebug for Firefox, or the inspector for Safari and Chrome, you can see that at page load a series of AJAX requests are made for data. Though I didn't dig through all of the data returned by those requests, I do see the data you're looking for in at least one of them:

    http://uberstrike.com/profile/all_stats/631163 
    

    So at page load JavaScript makes a series of AJAX requests back to the server to get all the data, then it manipulates the DOM to insert it all into the view.

    If you wanted, your PHP could directly request the URL I pasted above and json_decode the response. This would produce a data structure for you to use which includes that number in the kills_all_time property.

    Quick and dirty example:

    <?php
    $data_url = 'http://uberstrike.com/profile/all_stats/631163';
    
    $serialized_data = file_get_contents($data_url);
    
    $data = json_decode($serialized_data, true);
    
    var_dump($data['kills_all_time']);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀