duanjue6584 2013-06-12 16:53 采纳率: 100%
浏览 210
已采纳

获取带有动态内容的html源代码来进行正则表达式分析

In My project I need to get the html content of another webpage in our server. The problem is that particular page has some dynamic content and I need the data in that content to do a regx analysis.

sample content from the page

    <div id="loading" class="loading">ESPERE UN MOMENTO POR FAVOR...<br /><img src="images/cargador.gif" border="0" alt="ESPERE UN MOMENTO POR FAVOR..." /></div>
<p></p>
<div class="tabla_d">
<form method="post" action="xxx">
<div id="nresults"></div>
</form>
</div>

<script language="javascript">
function checkavailability() {
    jQuery("#loading").slideDown();
    jQuery.post("cart.php", { a: "noptions", sld: jQuery("#sld").val(), tld: jQuery("#tld").val(), checktype: 'transfer', ajax: 1 },
    function(data){
        $('html, body').animate({scrollTop: '550px'}, 800);
        jQuery("#nresults").html(data);
        jQuery("#nresults").slideDown();
        jQuery("#loading").slideUp();
    });
}

The content is loaded in the div tag with id="nreults". I can view the data when I inspect the element but I am not able to get the data using CURL. Is there any way I can do this? I am pretty new and any help would be appreciated.

  • 写回答

1条回答 默认 最新

  • dongzan2740 2013-06-12 17:54
    关注

    Not directly. You would need to use cURL to send the same request the javascript makes which would return you not the entire page, but the HTML thats dynamically loaded into #nresults.

    $ch = curl_init('cart.php');
    
    $values = array(
       'sld' => 'you need to figure out what this value should be',
       'a' => 'noptions',
       'tld' => 'you need to figure what this value should be',
       'checktype' => 'transfer',
       'ajax' => 1
    );
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $values);
    
    $html = curl_exec($ch);
    
    // run your regex on $html, though you probably dont want to do that
    // you should probably use DOMDocument instead to operate on the DOM
    // Unless you are just looking for a partuclar sring of text that has nothing
    // to do with the HTML structure of the document.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝