Home  >  Article  >  Backend Development  >  PHP采集代码

PHP采集代码

WBOY
WBOYOriginal
2016-06-13 13:38:07691browse

PHP采集代码求助
我想采集这个网站的列表商品http://www.taomanzu.com/category-16-4-1-10000-1.html,功能是,同时能采集商品的ID,和商品的名称,并且写入缓存中,如http://www.taomanzu.com/category-16-4-1-10000-1.html列表中的某个商品ID是:9914540199,标题是:纯棉磨毛卷边九分裤\工装九分裤\休闲九分裤 2色

让后我需要的是同时能采集到商品ID,和商品标题,能合成一个链接如
纯棉磨毛卷边九分裤\工装九分裤\休闲九分裤 2色

下面的这代码只能采集商品ID或者标题,请问如何修改才可以同时采集并且合并成一个链接!

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php //今日热门,10分钟更新一次
require 'global.php';
require 'gzdoc.php';
include 'config.php';


$id=$_GET["id"]; 
$pg=$_GET["pg"]; 

if($_GET['pg']==""){ $pg=0; }
$dir='cache';
if(!file_exists($dir)){ @mkdir($dir,0777); }
ob_start();
//女装
$lastflesh=@filemtime($dir."/Cache_NvZhuang_new.html");
if(!file_exists($dir."/Cache_NvZhuang_new.html") or ($lastflesh + ($flush * 60 * 60) <= $timestamp)){  //$flush * 60  一小时
    $openurl="http://www.taomanzu.com/category-16-4-1-10000-1.html";
    $file = curl($openurl);
    //开始处理一条一条的条数!!!
    $result='';
    if (preg_match_all('/<p class="taoke_title"><a href="tshow-(.*?).html" target="_blank">/is', $file, $list))

    
    {
        foreach ($list[1] as $i=>$k1 ) if ($i'.$k1.'</a>';
        }
    }
    $result_utf=iconv("GB2312","GB2312",$result);
    file_put_contents($dir."/Cache_NvZhuang_new.html",$result_utf);

}



else
{

}

?>

<?php GzDocOut;
?>


------解决方案--------------------
把你的正则表达式换成

([^

然后修改一下foreach就可以了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn