update composer
This commit is contained in:
parent
b820f2bd53
commit
e1058b8201
@ -45,7 +45,7 @@ $hj->setQuery(array('title'=>array('','text'),'url'=>array('a','href')),'#con_tw
|
||||
echo $hj->getData();
|
||||
|
||||
*/
|
||||
require 'phpQuery/phpQuery.php';
|
||||
namespace QueryList;
|
||||
class QueryList
|
||||
{
|
||||
private $regArr;
|
||||
@ -85,7 +85,7 @@ class QueryList
|
||||
* @param $class
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
* @throws QueryList_Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function run($class,$args = array())
|
||||
{
|
||||
@ -96,19 +96,19 @@ class QueryList
|
||||
/**
|
||||
* 获取任意实例
|
||||
* @return mixed
|
||||
* @throws QueryList_Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
$args = func_get_args();
|
||||
count($args) || $args = array('QueryList');
|
||||
count($args) || $args = array(self::class);
|
||||
$key = md5(serialize($args));
|
||||
$className = array_shift($args);
|
||||
if(!class_exists($className)) {
|
||||
throw new QueryList_Exception("no class {$className}");
|
||||
throw new \Exception("no class {$className}");
|
||||
}
|
||||
if(!isset(self::$instances[$key])) {
|
||||
$rc = new ReflectionClass($className);
|
||||
$rc = new \ReflectionClass($className);
|
||||
self::$instances[$key] = $rc->newInstanceArgs($args);
|
||||
}
|
||||
return self::$instances[$key];
|
||||
@ -173,8 +173,8 @@ class QueryList
|
||||
|
||||
private function _getList()
|
||||
{
|
||||
$this->inputEncoding && phpQuery::$defaultCharset = $this->inputEncoding;
|
||||
$document = phpQuery::newDocumentHTML($this->html);
|
||||
$this->inputEncoding && \phpQuery::$defaultCharset = $this->inputEncoding;
|
||||
$document = \phpQuery::newDocumentHTML($this->html);
|
||||
$this->qpHtml = $document->htmlOuter();
|
||||
if (!empty($this->regRange)) {
|
||||
$robj = pq($document)->find($this->regRange);
|
||||
@ -210,7 +210,7 @@ class QueryList
|
||||
} else {
|
||||
while (list($key, $reg_value) = each($this->regArr)) {
|
||||
if($key=='callback')continue;
|
||||
$document = phpQuery::newDocumentHTML($this->html);
|
||||
$document = \phpQuery::newDocumentHTML($this->html);
|
||||
$tags = isset($reg_value[2])?$reg_value[2]:'';
|
||||
$lobj = pq($document)->find($reg_value[0]);
|
||||
$i = 0;
|
||||
@ -241,7 +241,7 @@ class QueryList
|
||||
//编码转换
|
||||
$this->data = $this->_arrayConvertEncoding($this->data, $this->outputEncoding, $this->htmlEncoding);
|
||||
}
|
||||
phpQuery::$documents = array();
|
||||
\phpQuery::$documents = array();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -386,8 +386,8 @@ class QueryList
|
||||
foreach ($tags as $tag) {
|
||||
$tag_str .= $tag_str?','.$tag:$tag;
|
||||
}
|
||||
phpQuery::$defaultCharset = $this->inputEncoding?$this->inputEncoding:$this->htmlEncoding;
|
||||
$doc = phpQuery::newDocumentHTML($html);
|
||||
\phpQuery::$defaultCharset = $this->inputEncoding?$this->inputEncoding:$this->htmlEncoding;
|
||||
$doc = \phpQuery::newDocumentHTML($html);
|
||||
pq($doc)->find($tag_str)->remove();
|
||||
$html = pq($doc)->htmlOuter();
|
||||
$doc->unloadDocument();
|
||||
@ -396,10 +396,7 @@ class QueryList
|
||||
}
|
||||
}
|
||||
|
||||
class QueryList_Exception extends Exception{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
class Autoload
|
||||
{
|
||||
public static function load($className)
|
||||
@ -420,3 +417,4 @@ class Autoload
|
||||
|
||||
spl_autoload_register(array('Autoload','load'));
|
||||
|
||||
*/
|
@ -4,6 +4,7 @@
|
||||
"require": {
|
||||
"PHP":">=5.3.0",
|
||||
"jaeger/phpquery-single": "^0.9.5",
|
||||
"jaeger/querylist-ext-aquery":"*",
|
||||
"jaeger/curlmulti":"^1.0",
|
||||
"jaeger/http":"^0.1"
|
||||
},
|
||||
@ -13,5 +14,10 @@
|
||||
"name": "Jaeger",
|
||||
"email": "hj.q@qq.com"
|
||||
}
|
||||
]
|
||||
],
|
||||
"autoload":{
|
||||
"psr-4":{
|
||||
"QueryList\\":""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @Author: Jaeger <hj.q@qq.com>
|
||||
* @Date: 2015-11-11 17:52:40
|
||||
* @Last Modified by: Jaeger
|
||||
* @Last Modified time: 2015-11-16 09:57:56
|
||||
* @version 1.0
|
||||
* 扩展基类
|
||||
*/
|
||||
abstract class AQuery
|
||||
{
|
||||
abstract function run(array $args);
|
||||
|
||||
public function getInstance($className = 'QueryList', $params = null)
|
||||
{
|
||||
return QueryList::getInstance($className,$params);
|
||||
}
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @Author: Jaeger <hj.q@qq.com>
|
||||
* @Date: 2015-11-11 17:52:40
|
||||
* @Last Modified by: Jaeger
|
||||
* @Last Modified time: 2015-11-16 09:57:58
|
||||
* @version 1.0
|
||||
* 模拟登陆扩展
|
||||
*/
|
||||
class Login extends Request
|
||||
{
|
||||
private $http;
|
||||
public $html;
|
||||
|
||||
public function run(array $args)
|
||||
{
|
||||
$this->http = $this->hq($args);
|
||||
$this->html = $this->http->result;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get($url,$callback = null,$args = null)
|
||||
{
|
||||
$result = $this->http->get($url);
|
||||
return $this->getQL($result,$callback,$args);
|
||||
}
|
||||
|
||||
public function post($url,$data=array(),$callback = null,$args = null)
|
||||
{
|
||||
$result = $this->http->post($url,$data);
|
||||
return $this->getQL($result,$callback,$args);
|
||||
}
|
||||
|
||||
private function getQL($html,$callback = null,$args = null)
|
||||
{
|
||||
if(is_callable($callback)){
|
||||
$result = call_user_func($callback,$result,$args);
|
||||
}
|
||||
$ql = $this->getInstance();
|
||||
$ql->html = $html;
|
||||
return $ql;
|
||||
}
|
||||
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @Author: Jaeger <hj.q@qq.com>
|
||||
* @Date: 2015-11-11 17:52:40
|
||||
* @Last Modified by: Jaeger
|
||||
* @Last Modified time: 2015-11-16 09:57:14
|
||||
* @version 1.0
|
||||
* 多线程扩展
|
||||
*/
|
||||
class Multi extends AQuery
|
||||
{
|
||||
public $curl;
|
||||
private $args;
|
||||
|
||||
public function run(array $args)
|
||||
{
|
||||
$default = array(
|
||||
'curl' => array(
|
||||
'opt' => array(
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_AUTOREFERER => true,
|
||||
),
|
||||
'maxThread' => 100,
|
||||
'maxTry' => 3
|
||||
),
|
||||
'list' => array(),
|
||||
'success' => function(){},
|
||||
'error' => function(){},
|
||||
'start' => true
|
||||
);
|
||||
|
||||
$this->args = array_merge($default,$args);
|
||||
|
||||
$this->curl = $this->getInstance('CurlMulti');
|
||||
if(isset($this->args['curl'])){
|
||||
foreach ($this->args['curl'] as $k => $v) {
|
||||
$this->curl->$k = $v;
|
||||
}
|
||||
}
|
||||
$this->add($this->args['list']);
|
||||
|
||||
return $this->args['start']?$this->start():$this;
|
||||
}
|
||||
|
||||
public function add($urls,$success = false,$error = false)
|
||||
{
|
||||
if(!is_array($urls)){
|
||||
$urls = array($urls);
|
||||
}
|
||||
foreach ($urls as $url) {
|
||||
$this->curl->add(
|
||||
array(
|
||||
'url' => $url,
|
||||
'args' => $this,
|
||||
'opt' => array(
|
||||
CURLOPT_REFERER => $url
|
||||
)
|
||||
),
|
||||
$success?$success:$this->args['success'],
|
||||
$error?$error:$this->args['error']
|
||||
);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function start()
|
||||
{
|
||||
$this->curl->start();
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @Author: Jaeger <hj.q@qq.com>
|
||||
* @Date: 2015-07-15 23:27:52
|
||||
* @Last Modified by: Jaeger
|
||||
* @Last Modified time: 2015-11-16 11:01:19
|
||||
* @version 1.0
|
||||
* 网络操作扩展
|
||||
*/
|
||||
|
||||
class Request extends AQuery
|
||||
{
|
||||
|
||||
protected function hq(array $args)
|
||||
{
|
||||
$args = array(
|
||||
'http' => isset($args['http'])?$args['http']:$args,
|
||||
'callback' => isset($args['callback'])?$args['callback']:'',
|
||||
'args' => isset($args['args'])?$args['args']:''
|
||||
);
|
||||
$http = $this->getInstance('Http');
|
||||
$http->initialize($args['http']);
|
||||
$http->execute();
|
||||
if(!empty($args['callback'])){
|
||||
$http->result = call_user_func($args['callback'],$http->result,$args['args']);
|
||||
}
|
||||
return $http;
|
||||
}
|
||||
|
||||
public function run(array $args)
|
||||
{
|
||||
$http = $this->hq($args);
|
||||
$ql = $this->getInstance();
|
||||
$ql->html = $http->result;
|
||||
return $ql;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user