PinPHP后台批量采集的功能二次开发修改实现
使用PinPHP有一段时间了,利用PinPHP在Sae上搭了个环境,运营一个月左右的《时尚美汇》,所以最近也一直在研究这套程序,顺便做些二次开发,加入些自己的想法。例如之前写过的博文:加入人人网帐号登录(淘宝登录其实也做了,只是在淘宝应用中心上用)、修改PinPHP采集。
好吧,今天来说说关于PinPHP后台批量采集的功能二次开发修改实现,本人一开始接解pinphp,使用的是2.1测试版,
到现在官方已经发布了2.2版,但遗憾的是,大家一值期待的批量采集功能并没有如愿发布,所以本人自己尝试去修改修改,
其实程序早在半个月前就写好了,只是自己在用,一方面工作有点忙,另一方面自己测试一段时间,顺便完善一下。
实现原现很简单,主要是修改采集界面,加了几个checkbox,用于传递要采集的id、关键字等。
1、修改:admin\Tpl\default\items_collect\collect.html页面,28行左右。
Copy to Clipboard引用的内容:[www.bkjia.com]官方应该是有尝试去做批量采集,因为此页面上有关于批量采集的代码未完成,只是注释了。
2、然后在\admin\Lib\Action\items_collectAction.class.php上增加了一个函数,以及略修改原采集函数
Copy to Clipboard引用的内容:[www.bkjia.com] function ajaxCollect(){set_time_limit(0);
$subname=$_REQUEST['subname'];
$arrUrls=array();
foreach($_REQUEST['cate'] as $k=>$v){
if(!empty($subname[$k])){
$arrUrls[]='http://mmlike.sinaapp.com/mlike_admin.php?a=taobao_collect_jump&m=items_collect&pages=1&cate_id='.$v.'&keywords='.$subname[$k];
}
}
$this->assign('url',json_encode($arrUrls));
$this->display('ajaxCollect');
}
这一句有一些信息要注意一下
Copy to Clipboard引用的内容:[www.bkjia.com] $arrUrls[]='http://mmlike.sinaapp.com/mlike_admin.php?a=taobao_collect_jump&m=items_collect&pages=1&cate_id='.$v.'&keywords='.$subname[$k];page=1是采集一页,每页40个商品,如果需要一次采集更多商品,可自行修改,但不建议填太大的值,一方面采集时间长,另一方面,淘宝api请求可能会太频繁。
修改public function collect()函数,前半部分的if改成
Copy to Clipboard引用的内容:[www.bkjia.com] if(isset($_REQUEST['dosubmit'])){/******批量采集*******/
$cate=implode(',',$_REQUEST['cate']);
$this->ajaxCollect();
//header("location:".U('items_collect/taobao_batch_collect_jump?act=batch&cate='.$cate));
exit;
/******批量采集*******/
}
3、在模板里增加一个,\admin\Tpl\default\items_collect\ajaxCollect.html
Copy to Clipboard引用的内容:[www.bkjia.com]了解php和js的朋友应该看懂,将组装好的采集url,以json形式放在js里,利用setInterval定时器去定时执行ajax请求,遍历所有的url
直到完成。一开始用setInterval而不是直接for遍历是担心分类多时,太频繁请求淘宝api会导致部份采集不成功。
上面的ajax使用异步请求,之前尝试使用同步去获取,是为了方便捕获到那个采集成功,哪个不成功,以便手动去采集,
测试了一段时间,虽然效果是达到了,但由于分类太多一次采集的时候,浏览器会卡,而已采集总时间也变长漫长。现还是使用
异步,不卡,缩短采集时间,虽然也可以实现失败捕足,但要修改更多的代码,这个有时间有研究。现在的效果如下
用%比显示进度,最后会显示完成度和有多少个失败,至于失败的再采集一次,又或者自己去检查哪个未采集手动采集。
这个修改后,原采集功能也可正常使用。
重申一下,本人使用的是pinphp2.1测试版,其他版本若要修改,可作为参考,以下是修改文件的打包,不建议直接覆盖,最好
对比一下代码,如要覆盖,请先备份原文件,以便恢复。
点击下载:pinphp批量采集
教程来源:http://meego123.net/?post=140

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
