阿里云ACE页面抓取(FetchURL)

2014/09/01 3364点热度 0人点赞 0条评论

服务的获取
通过 Alibaba::应用 SDK 名 来初始化相关 SDK。
服务获取
$storage = Alibaba::Storage('存储空间名称'); //使用指定存储空间
$cache = Alibaba::Cache('缓存空间名称'); //使用指定缓存空间,不写参数则使用系统默认缓存空间
$cur=Alibaba::Curl($url, $method, $data);
缓存服务
方法列表
方法 参数 返回值 说明
get $key string|false $key 为要取出的数据的键名,也可以
是一个包含多个键名的数组
set $key,$value[, $exp] set $value 为要存储的值,$exp 为过期
时间
add $key, $value, $exp add
replace $key, $value, $exp replace
delete $key delete
decrement $key[, $step = 1] decrement $step 为步长,默认为 1
increment $key[, $step = 1] increment
示例代码
//指定一个缓存空间:
Alibaba::Cache('缓存空间名称')->add('key1', time());
Alibaba::Cache('缓存空间名称')->set('key2', time());
$array = array(
'key1', 'key2'
);
$values = Alibaba::Cache('缓存空间名称')->get($array);
$values = Alibaba::Cache('缓存空间名称')->get('key1');print_r($values);
存储服务
方法列表
方法 参数 返回值 说明
get $object[, $path] boolean|string 失败返回 false,
如果传入$path 成功返回 true,
未传$path 则成功返回文件内容
本方法将取出$object 的内容并保存
到$path 的路径。 $object 为要取出
的对象的名称,$path 为要保存的本
地路径
getMeta $object array 取得文件的元信息
saveText $object, 
$content[, 
$exp_time]
boolean 将$content 的内容保存到名为
$object 的位置,$exp 为过期时间
saveFile $object, $file boolean 将本地文件$file 上传到$object 的位

fileExists $object boolean 检查$object 是否存在
delete $object boolean 删除$object
move $from, $to boolean 将 Storage 上的文件$from 移动到
$to 的位置($to 是新的文件名)
copy $from, $to boolean 将 Storage 上的文件$from 复制到
$to 的位置($to 是新的文件名)
示例代码
//指定一个存储空间:
$storage = Alibaba::Storage('存储空间名称');
$res = $storage ->saveText("_the_test_case_key", "anything", -11);
echo '通过文本上传文件:';
var_dump($res);
echo '检查文件是否存在:';
$res = $storage ->fileExists("显然不存在的 object");
var_dump($res);
$res = $storage ->fileExists("_the_test_case_key");
var_dump($res);
echo '取得 meta 信息:';
$res = $storage ->getMeta("_the_test_case_key");
var_dump($res);echo '通过本地文件上传文件:';
$res = $storage ->saveFile("_the_test_case_key", "./1.txt");
var_dump($res);
echo '拷贝文件(预期成功):';
$res = $storage ->move("_the_test_case_key", "_the_test_case_key_1");
var_dump($res);
echo '删除:';
$res = $storage ->delete("_the_test_case_key");
var_dump($res);
echo '移动文件(预期失败):';
$res = $storage ->move("_the_test_case_key", "_the_test_case_key_1");
var_dump($res);
echo '获取:';
$res = $storage ->get("_the_test_case_key_1");
var_dump($res);
echo '删除:';
$res = $storage ->delete("_the_test_case_key_1");
页面抓取服务
方法列表
参数 可用值 说明
$url string 字符串型的页面地址
$method 'post'|'get' 限定为两者之一
data array() 必须为键值对的数组,其中第一维为所传的值
示例代码
//GET 请求
//以下实例为最简单的页面 GET 请求,两种写法等价。
$curl = Alibaba::Curl('http://www.aliyun.com/');
var_dump($curl);$curl = Alibaba::Curl('http://www.aliyun.com/', 'get');
var_dump($curl);
//如果 GET 请求时传递了$data,则$data 为 GET 请求中的参数,上例所请求的地址将
是: http://www.aliyun.com/?test=123
$curl = Alibaba::Curl('http://www.aliyun.com/', 'get', array('test'=>123));
var_dump($curl);
//POST 请求
// POST 请求需要至少传递 2 个参数:
$curl = Alibaba::Curl('http://www.aliyun.com/', 'post');
//如果传递了$data,则$data 为 POST 的内容。
$curl = Alibaba::Curl('http://localhost/test/redirect.php', 'post', array('test'=>123));

幸运猪头

保持饥渴的专注,追求最佳的品质

文章评论