在我的代碼中,當我將html
內容分配給變量但不與url path
一起使用時,我的Regexp
正常工作。我得到空陣列。正則表達式不能使用cURL url內容
<?php
$productmfgno = "154637401";
$url = "http://www.pandorasoem.com/search#q=".$productmfgno;
$ch1= curl_init();
curl_setopt ($ch1, CURLOPT_URL, $url);
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch1,CURLOPT_VERBOSE,1);
curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)');
curl_setopt ($ch1, CURLOPT_REFERER,'http://www.google.com'); //just a fake referer
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1,CURLOPT_POST,0);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 20);
$htmlContent= curl_exec($ch1);
curl_close($ch1);
/* It works when I assign this html content to $htmlContent variable but not working with cURL url
$htmlContent = '<div class="findify-navigation-header findify-clearfix"> <div class="findify-pagination findify-push-right"></div> <div class="findify-header">Showing 2 results for <span class="findify-query">"154637401"</span>. <span id="findify-didyoumean"></span></div> </div>';
*/
preg_match_all('/<div.*class=\"findify\-header\".*?>(.*?)<span.*class=\"findify-query\">.*?<\/div>/Us', $htmlContent, $count);
print_r($count);
預期結果 - Showing 2 results for
這樣我就可以獲取該結果計數。
post sample respone – Vishnu
我得到空數組。 – Nikita
http://www.pandorasoem.com/search#q=154637401 - 此頁面上的源碼不包含您提到的任何html,它正在通過javascript加載結果 – Vishnu