2013-06-12 2 views
0

나의 프로젝트에서는 우리의 서버에있는 다른 웹 페이지의 html 내용을 얻어야한다. 문제는 특정 페이지에 일부 동적 컨텐트가 있으며 regx 분석을 수행하기 위해 해당 컨텐트의 데이터가 필요하다는 것입니다. 페이지동적 인 내용을 가진 html 원시 코드를 얻는 정규식 분석

<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을 사용하여 데이터를 가져올 수 없습니다. 내가 이것을 할 수있는 방법이 있습니까? 나는 꽤 새롭고 도움이 될 것입니다.

+0

해당 div에는 비동기 적으로로드되는 데이터가 있으며, 이는 브라우저가 자바 스크립트로 콘텐츠를로드한다는 것을 의미합니다. CURL은 처리가 완료되기 전에 페이지에서 표준 출력을 반환합니다. AFAIK는이 정보를 포착 할 수 없습니다. – phpisuber01

+0

@ phpisuber01 : JS로 페이지를 치는 것이 아니라 JS가했던 것처럼 cart.php에 'POST'요청을 할 수 있습니다. 처음. 물론 그는 모든 포스트 가치가 필요한 것을 파악해야 할 것입니다. – prodigitalson

+0

게시물 데이터를 말릴 수 있습니까? 그렇다면 어떻게해야합니까? –

답변

0

직접적으로. 당신은 cURL을 사용하여 javascript가 여러분에게 전체 페이지가 아닌 return을 보내지 만, HTML은 동적으로 #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. 
+0

퍼펙트 덕분에 많은 도움이되었습니다. –

관련 문제