利用phantomjs模拟QQ自动登录

PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

开搞,代码实现如下。

var page = require('webpage').create();
var fs = require("fs");
page.settings.userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4';
page.open('http://ui.ptlogin2.qq.com/cgi-bin/login?pt_no_onekey=1&style=9&appid=1006102&s_url=http%3A%2F%2Fxiaoqu.qq.com%2Fmobile%2Fbarindex.html%3F_lv%3D29313%26_bid%3D128%26_wv%3D1027%26from%3Dshare_link%23bid%3D37469%26type%3D%26source%3Dindex%26scene%3Drecent%26from%3Ddongtai%26webview%3D1&low_login=0&hln_css=http%3A%2F%2Fpub.idqqimg.com%2Fqqun%2Fxiaoqu%2Fmobile%2Fimg%2Fnopack%2Flogin-logo.png', function(status){
    if (status == 'success') {
        page.render('index.png');
        setTimeout(function() {
            page.evaluate(function() {
                document.getElementById('u').value = 'QQ号码';
                document.getElementById('p').value = 'QQ密码';
                pt.check(false);
                //document.getElementById('go').click(); //pt.check()或.click()
            });
            setTimeout(function() {
                file = fs.open("cookie.log", 'w');
                file.write(JSON.stringify(page.cookies));
                file.close();
                phantom.exit();
            }, 2000);
        }, 1000);
    }
});

cookie会写入到当前目录下的cookie.log文件,有了cookie接下来的事情就简单多了。使用php或js将cookie种到浏览器下即可。

浏览全部

centos 安装 PhantomJS

1. 安装步骤

1.1 在服务器上新建想要下载和安装的目录:

如mkdir  PhantomJS

1.2 下载PhantomJS安装包

wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2

 

 

执行结果如下图:

1.3 解压工具包

tar -xjvf phantomjs-2.1.1-linux-x86_64.tar.bz2

 

执行时报如下错误:

tar (child): cannot run bzip2: No such file or directory

出现上述错误,请安装bzip2

执行指令:

 

yum -y install bzip2

 

再次执行解压指令:

成功完成解压。

1.4 将可执行文件放入系统路径

sudo ln -s ~/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs

 

1.5 安装依赖——fontconfig和freetype:

yum install fontconfig

 

yum install freetype

 



1.6 在终端下测试Phantomjs

注意系统目录为/usr/bin/
至此成功

centos 安装 php-v8js

Centos 安装v8js

yum install php-pear

yum install re2c

yum install v8-devel

pecl install v8js-0.1.3
// if failed, need to download v8js-0.1.3 and manually install it

// modify b8js.cc and add the blow info line 1

#define PHP_V8_VERSION “0.1.3”

phpize
./configure –with-v8js
make
make test
make install

echo “extension=v8js.so” >> /etc/php.ini

ubuntu 安装 php-v8js扩展

直接pecl install v8js……报错。。

root@ubuntu:/usr/local/src/v8js-1.3.5# ./configure --with-php-config=/usr/local/php7/bin/php-config 
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php7
checking for PHP includes... -I/usr/local/php7/include/php -I/usr/local/php7/include/php/main -I/usr/local/php7/include/php/TSRM -I/usr/local/php7/include/php/Zend -I/usr/local/php7/include/php/ext -I/usr/local/php7/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303
checking for PHP installed headers prefix... /usr/local/php7/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 0.13.5 (ok)
checking for gawk... gawk
checking for V8 javascript Engine... yes, shared
checking for V8 files in default path... found in /usr
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for C standard version... c++11
checking how to allow c++11 narrowing... 
checking for libv8_libplatform... checking for libv8_libplatform... configure: error: could not find libv8_libplatform library

 

系统自带的libv8版本太低了。

sudo add-apt-repository ppa:pinepain/libv8
sudo apt-get update

 

卸載原先的libv8-dev,執行apt-get install libv8-6.6-dev

nice

Build process completed successfully
Installing '/usr/lib/php5/20121212/v8js.so'
install ok: channel://pecl.php.net/v8js-0.6.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=v8js.so" to php.ini

 

Centos 清理日志文件

使用CentOS系统的时候,经常会遇到系统日志文件非常大的情况,如果直接删除,会导致日志错误,不再生成日志,这时,我们可以使用下面的方法清空日志。

* [Centos6]
* [Centos7]

CentOS 6系统

cat /dev/null > /var/log/boot.log
cat /dev/null > /var/log/btmp
cat /dev/null > /var/log/cron
cat /dev/null > /var/log/dmesg
cat /dev/null > /var/log/dracut.log
cat /dev/null > /var/log/lastlog
cat /dev/null > /var/log/maillog
cat /dev/null > /var/log/messages
cat /dev/null > /var/log/secure
cat /dev/null > /var/log/spooler
cat /dev/null > /var/log/tallylog
cat /dev/null > /var/log/wtmp
cat /dev/null > /var/log/yum.log

CentOS 7系统

cat /dev/null > /var/log/boot.log
cat /dev/null > /var/log/btmp
cat /dev/null > /var/log/cron
cat /dev/null > /var/log/dmesg
cat /dev/null > /var/log/firewalld
cat /dev/null > /var/log/grubby
cat /dev/null > /var/log/lastlog
cat /dev/null > /var/log/mail.info
cat /dev/null > /var/log/maillog
cat /dev/null > /var/log/messages
cat /dev/null > /var/log/secure
cat /dev/null > /var/log/spooler
cat /dev/null > /var/log/syslog
cat /dev/null > /var/log/tallylog
cat /dev/null > /var/log/wpa_supplicant.log
cat /dev/null > /var/log/wtmp
cat /dev/null > /var/log/yum.log

 

 

Debian安装 aria2

为什么是Debian??因为我的树莓派用的是debian!23333~~~~

aria2 一个方便的下载工具,支持  HTTP/HTTPSFTPSFTPBitTorrent 和Metalink 。可以通过内置的 JSON-RPC 和XML-RPC 接口来使用。参考 github 项目aria2

注意这里使用 Debian进行搭建。不要使用 centos,为什么呢?因为centos 上好多对应的依赖包都找不到,软件版本过低等问题。如果你硬要搭建,可以参考 Centos6编译安装最新Aria2 1.27.1——带你临近网速极限浏览全部