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.

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

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么