繁体   English   中英

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

[英]getting html source code with dynamic content to do regular expression analysis

在我的项目中,我需要获取服务器中另一个网页的html内容。 问题是特定页面具有一些动态内容,而我需要该内容中的数据才能进行regx分析。

页面中的样本内容

    <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();
    });
}

内容以id="nreults"加载到div标签中。 检查元素时可以查看数据,但无法使用CURL获取数据。 有什么办法可以做到吗? 我很新,任何帮助将不胜感激。

不直接。 您将需要使用cURL发送javascript发出的相同请求,该请求将返回整个页面,而不是整个页面,而是动态加载到#nresults的HTML。

$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.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM