我试图使用php cURL和preg_match从下面的html页面/链接中提取价格。基本上,我期待这个代码输出4,550,但由于某种原因,我得到php cURL。 preg_match,从xhtml中提取文本
Notice: Undefined offset: 1 in C:\wamp\www\test.php on line 22
我觉得模式是正确的,因为如果我把HTML本身的变量和逃避“”它的工作原理! 。 另外,如果我输出(echo $ result;)它显示从foxtons网站正确抓住的HTML,所以我无法弄清楚为什么整个事情不起作用。我需要做这项工作,如果您能告诉我为什么会生成该通知,以及为什么我的当前脚本不起作用,我将不胜感激。
$url = " http://www.foxtons.co.uk/search?bedrooms_from=0&property_id=727717 "; $ch = curl_init($url);curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_exec($ch); curl_close($ch); $result2 = str_replace('"', '\"', $result);
$tagname1= ");</script> "; $tagname2= "</noscript> per month</a>";
$pattern = "/$tagname1(.*?)$tagname2/"; preg_match($pattern, $result, $matches); $prices = $matches[1]; print_r($prices); ?>
为什么你定义$ result2如果你不使用它? – Artefacto 2010-05-15 00:02:28