duanchun6148 2012-04-16 00:55
浏览 48
已采纳

代码抓取工具抓取异步GA代码

Hello I have a php code crawler to detect a website if it has a Asynchronous Google Code. here's the snippet to detect the the asynch google Code:

$async_ga_string = "ga.async";

if(!strpos($str, $async_ga_string))$async_ga = '';
            else $async_ga = 'yes';

It works fine. But what I exactly needed is for me to able to get the asynch UA code in this google code snippet:

     var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-2595901-1']);
  _gaq.push(['_trackPageview']);

I need to get the 'UA-2595901-1'

  • 写回答

1条回答 默认 最新

  • duannaxin9975 2012-04-16 01:48
    关注

    It's an imperfect solution, but the Google Analytics Account ID is almost unique enough to find it using a simple Regular Expression:

    <?php
    $gaRegExp = '/UA-\d+-\d+/';
    
    $testText = "var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-2595901-1']);
      _gaq.push(['_trackPageview']);"
    
    preg_match( $gaRegExp , $testText , $matches )
    
    // Returns, within the $matches variable, the following
    // array (
    //  0 => 'UA-2595901-1',
    // )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法