搜索
系统检测到您的用户名不符合规范:

PHP使用QueryList轻松实现一个百度网盘资源搜索引擎

浏览:3672 发布日期:2017年10月07日 分类:功能实现 关键字: QueryList 采集 phpQueryList
PHP实现一个百度网盘资源搜索引擎
QueryList使用jQuery的方式来做采集,拥有丰富的插件。

下面来演示QueryList使用Baidu搜索引擎插件轻松实现站内搜索。

安装
使用Composer安装:

安装QueryListcomposer require jaeger/querylistGitHub: https://github.com/jae-jae/QueryList

安装Baidu搜索引擎插件composer require jaeger/querylist-rule-baiduGitHub: https://github.com/jae-jae/QueryList-PhantomJS

插件API
Baidu baidu($pageNumber = 10):获取百度搜索引擎
class Baidu:

Baidu search($keyword):设置搜索关键词
Baidu setHttpOpt(array $httpOpt = []):设置HTTP选项,查看: GuzzleHttp options
int getCount():获取搜索结果总条数
int getCountPage():获取搜索结果总页数
Collection page($page = 1,$realURL = false):获取搜索结果

使用

实现一个百度网盘资源搜索引擎:<?php

require 'vendor/autoload.php';

use QL\QueryList;
use QL\Ext\Baidu;

$ql = QueryList::use(Baidu::class);

// 搜索百度网盘网站,包含‘百度’关键词的资源
$searcher = $ql->baidu()->search('site:pan.baidu.com 百度');

// 获取第一页数据,并获取真实URL连接地址
$data = $searcher->page(1,true);

print_r($data->all());
抓取结果:Array
(
[0] => Array
(
[title] => 百度网盘_享你所想
[link] => http://pan.baidu.com/
)
[1] => Array
(
[title] => 百度网盘 客户端下载
[link] => https://pan.baidu.com/download
)
[2] => Array
(
[title] => 百度网盘-开放平台
[link] => https://pan.baidu.com/platform/read
)
// ....
)
更多用法$baidu = $ql->baidu(15); // 设置每页搜索15条结果
$searcher = $baidu->search('QueryList');
$count = $searcher->getCount(); // 获取搜索结果总条数
$data = $searcher->page(1);
$data = $searcher->page(2);

$searcher = $baidu->search('php');
$countPage = $searcher->getCountPage(); // 获取搜索结果总页数
for ($page = 1; $page <= $countPage; $page++)
{
$data = $searcher->page($page);
}

$data = $searcher->setHttpOpt([
// 设置http代理
'proxy' => 'http://222.141.11.17:8118',
// Set the timeout time in seconds
'timeout' => 30,
])->page(1);
Google搜索引擎插件
当然除了Baidu搜索引擎插件,QueryList也有Google搜索引擎插件,也可以实现同样的功能。

文档: https://doc.querylist.cc/site/index/doc/43
GitHub: https://github.com/jae-jae/QueryList-Rule-Google
评论() 相关
后面还有条评论,
评论支持使用[code][/code]标签添加代码
您需要登录后才可以评论 登录 | 立即注册
收藏
jae
积分:1347 等级:LV3
热点推荐
(追記) (追記ここまで)
最新更新

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /