页面定时抓取与通知,苹果产品自动到货通知,macbook ipad iphone抢定通知

有朋友想入手苹果一款电脑,但是官网总没货,总去看嫌太麻烦,就写了个程序,自动检查是否有货,有货就自动发送邮件通知,邮件可以是qq邮箱,qq邮件通常都关联微信,只要收到邮件 微信就叫。。。你懂的

思路是:定时每隔5分钟执行一个脚本自动抓取指定网页内容,分析是否有购买按钮,如果有购买按钮则发送邮件通知

本文用到的几个包含文件
Jcurl.php : curl抓取类
Jutil.php :常用方法,本例暂未用到
phpQuery.php :html分析类
class.phpmailer.php :邮件发送类
class.smtp.php :邮件发送类
在这里可以找到 http://git.oschina.net/thendfeel/xxtime

好了,上代码 /root/bin/checkApple.php

<?php
include 'xxtime/Jcurl.php';
include 'xxtime/Jutil.php';
include 'xxtime/phpQuery.php';
include 'xxtime/PHPMailer/class.phpmailer.php';

$jcurl = new Jcurl();
$url = 'http://store.apple.com/cn/product/FD212CH/A';
$page = $jcurl->get($url);

$doc = phpQuery::newDocument($page);
$ret = pq('.transactional')->attr('title');
$time = date('m-d H:i:s');
if ($ret == '添加到购物车') {
    echo "{$time} get product @";
    sendMail();
} else {
    echo "{$time} no productrn";
}

function sendMail()
{
    $mail = new PHPMailer();
    $body = '有货了,试试看 http://store.apple.com/cn/product/FD212CH/A';
    $mail->CharSet = "UTF-8";
    $mail->IsSMTP();
    $mail->SMTPDebug = 0;
    $mail->SMTPAuth = TRUE;
    $mail->SMTPSecure = "ssl";
    $mail->Host = "smtp.exmail.qq.com"; // 发件服务器
    $mail->Port = 465; // 服务器端口
    $mail->Username = "service@xxtime.com"; // 发件地址
    $mail->Password = "123456789"; // 邮箱密码
    $mail->Subject = 'Notice From XXtime';
    $mail->SetFrom('service@xxtime.com', 'xxtime service');
    $mail->AddReplyTo('service@xxtime.com', 'xxtime service');
    $mail->AddAddress('joe@xxtime.com', "Joe"); // 收件地址
    $mail->MsgHTML($body);

    if (! $mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo . "rn";
    } else {
        echo "Message sent successfullyrn";
    }
}

我们让检测脚本每隔5分钟检测一次,然后我们在linux上加一条任务,执行

crontab -e

加入如下:

*/5 * * * * php /root/bin/checkApple.php >> /root/bin/log_apple.txt

/root/bin/checkApple.php 是脚本的位置, /root/bin/log_apple.txt 是输出的日志
不懂linux定时任务的自己补,我说的多了就都废话了。。。

libXrender.so.1: cannot open shared object file: No such file or directory Couldn't load XPCOM.

centos 的yum命令 有一个很有意思的用法,估计很多人都不知到 yum whatprovides ***
例如:yum whatprovides libXrender.so.1
比如遇到了一些报错问题
报错:

XPCOMGlueLoad error for file /home/Joe/Downloads/firefox/libxul.so:
libXrender.so.1: cannot open shared object file: No such file or directory
Couldn't load XPCOM.

原因是找不到libXrender.so.1
我们用命令查找下安装包

yum whatprovides libXrender.so.1
[root@Joe-PC firefox]# yum whatprovides libXrender.so.1
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * epel: mirrors.neusoft.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirror.bit.edu.cn
libXrender-0.9.7-2.el6.i686 : X.Org X11 libXrender runtime library
Repo        : base
Matched from:
Other       : libXrender.so.1



libXrender-0.9.7-2.el6.i686 : X.Org X11 libXrender runtime library
Repo        : installed
Matched from:
Other       : Provides-match: libXrender.so.1

我们可以看到缺少一个叫libXrender-0.9.7-2.el6.i686的安装包
下面安装

yum install libXrender-0.9.7-2.el6.i686