用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3555|回复: 0
收起左侧

phpquery进行搜索采集(原创二)

[复制链接]
发表于 2012-10-5 11:57:05 | 显示全部楼层 |阅读模式
本帖最后由 ★わ浪漫少帅 于 2012-10-5 12:01 编辑
PHP复制代码
 
[color=#003000]        //因为执行时间较长,所以设置运行时间不被限制---编码utf-8
       ini_set('max_execution_time', '0');
        require_once dirname(__FILE__).'./phpQuery.php';
        //比价网---搜索
        $keyword = 'ipad';
        $http = 'http://search.beargoo.com.cn/search.php?kw='.$keyword;
        $html = file_get_contents($http);
        phpquery::newDocumentHTML($html,'utf-8');
        //我们真正要的数据就是全部中的数据.
        //获得产品的页数
        $page_total = pq('div.pagination li:not(:last):last')->text();
        //循环页数,拿到所有产品
        for($i=1;$i<=$page_total;$i++){
                $page_url = $http.'&page='.$i;
                $html = file_get_contents($page_url);
                phpquery::newDocumentHTML($html,'utf-8');
                $product_lists = pq('div.list>div.productlist');
                foreach($product_lists as $product_list){
                        $product_list = pq($product_list);
                        //产品url
                        $product_url = $product_list->find('dt>a')->attr('href');
                        //产品名称
                        $product_title = $product_list->find('dt>a')->text();
                        //产品价格
                        $product_price = $product_list->find('li>b')->text();
                        exit($product_title.$product_price);
                }
        }
[/i][/color]
复制代码

本版积分规则