时间:2021-07-01 10:21:17 帮助过:26人阅读
$url = 'http://www.meishij.net/chufang/diy/?page=1#listnav';$opts = array( 'http'=>array( 'user_agent' => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)", ) ); $context = stream_context_create($opts); $con = file_get_contents("$url", false, $context);//条目$preg ='#https://www.gxlcms.com/(.*)#'; preg_match_all($preg, $con, $arr); //搜索内容赋值给数组 for($i=0;$i<20;$i++) //单页面截取{ //print_r($arr[0][$i]); $ss=$arr[2][$i]; echo $ss; echo ""; $opts = array( 'http'=>array( 'user_agent' => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)", ) ); $context = stream_context_create($opts); $cons = file_get_contents("$ss", false, $context);//标题$preg ='#https://www.gxlcms.com/(.*)
#'; preg_match_all($preg, $cons, $arr); //搜索内容赋值给数组 print_r($arr[0][0]);//内容$preg ='#https://www.gxlcms.com/(.*)https://www.gxlcms.com/(.*)
#'; preg_match_all($preg, $cons, $arr); //搜索内容赋值给数组 print_r($arr[0][0]);echo "";print_r($arr[0][1]);echo "";print_r($arr[0][2]);echo "";//图片$preg ='##'; preg_match_all($preg, $cons, $arr); //搜索内容赋值给数组 print_r($arr[0][0]);echo "";print_r($arr[0][1]);echo "";print_r($arr[0][2]);echo "";print_r($arr[0][3]);echo "";print_r($arr[0][4]);echo "";print_r($arr[0][5]);echo "";print_r($arr[0][6]); }
哪位高手知道告诉下,3Q、
求解,为啥循环不过去。
print_r $arr;//看看$arr什么内容
preg_match_all($preg, $con, $arr); //搜索内容赋值给数组
for($i=0;$i<20;$i++) //单页面截取
{
//print_r($arr[0][$i]);
$ss=$arr[2][$i];
echo $ss;
echo "";
$opts = array(
'http'=>array(
'user_agent' => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)",
)
);
$context = stream_context_create($opts);
$cons = file_get_contents("$ss", false, $context);
print_r($cons);
die();
//标题
$preg ='#
https://www.gxlcms.com/(.*)https://www.gxlcms.com/(.*)
#';