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 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?