doutangxi2144 2013-09-17 23:19
浏览 14
已采纳

使用Preg_Match在PHP中刮取Javascript

I am scraping a site with cURL and returning the output, then putting it through the preg_match() function to retrieve certain things. When I try to scrape the following it doesn't show anything.

preg_match('/var b=new (.*)var p=new /i', $bountyHTML, $ting);
$chou = $ting[1];
echo $chou;

The section in $bountyHTML I am trying to scrape from looks like this:

<script>
    function fsb(x) {
      var b=new Array(101,55,100,99,52,49,57,50,54,56,51,55,54,49,51,50,101,50,49,50,100,54,49,97,50,53,52,99,100,57,54,53,51,100,49,54,55,38,101,101,49,104,61,101,61,50,50,49,56,99,110,111,78,50,109,114,111,102,38,52,61,100,101,55,105,95,98,116,115,105,51,108,48,116,105,97,104,63,112,104,52,112,97,49,46,121,55,56,52,101,102,54,50,116,110,117,52,111,98,47,101,54,57,52,57,101,53,99,98,102,56,48,98,51);
      var p=new Array(1,0,1,0,0,1,0,1,1,1,1,1,1,0,1,0,1,0,1,0,0,1,0,1,1,1,1,0,0,1,0,1,0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,0,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,0,1,1,0,1,1,1,0,1,0,1,1,0,1,1,1,1,0,1,0,0,1,1,0,0,0,0,0,0,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0);       
      var bountyForm = document.getElementById('bountyForm');
      bountyForm.action = c(b,p) + x;
      return true;
    }
  </script>

Any ideas why it wouldn't be returning anything? Thanks!

  • 写回答

1条回答 默认 最新

  • doumouyi4039 2013-09-17 23:28
    关注
    preg_match('/var b=new (.*)var p=new /is', $bountyHTML, $ting);
    

    http://php.net/manual/en/reference.pcre.pattern.modifiers.php

    s (PCRE_DOTALL) If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路