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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵