新浪短网址接口的稳定性和跳转速度还是很给力的,现给出其API说明。 该接口支持两种返回格式:xml和json 对应的URL请求地址为:
xml:http://api.t.sina.com.cn/short_url/shorten.xml json:http://api.t.sina.com.cn/short_url/shorten.json
请求方式:GET 请求参数: source:应用的appkey url_long:需要转换的长链接
新浪短网址接口的稳定性和跳转速度还是很给力的,现给出其API说明。 该接口支持两种返回格式:xml和json 对应的URL请求地址为:
xml:http://api.t.sina.com.cn/short_url/shorten.xml json:http://api.t.sina.com.cn/short_url/shorten.json
请求方式:GET 请求参数: source:应用的appkey url_long:需要转换的长链接
1,打开终端 2,输入如下命令回车执行 sudo pmset -a GPUSwitch 0 3,输入密码确认执行如上命令 4,重启搞定。
说明:
0 - 强制使用核显 1 - 强制使用独显(相当于在偏好设置-效能 里去掉自动切换显卡这个选项) 2 - 自动切换显卡
环境要求
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种到浏览器下即可。
#!/bin/bash
#此脚本为自动封ssh登录次数
num=10 #输错密码上限
for i in `awk '/Failed/{print (NF-3)}' /var/log/secure|sort|uniq -c|sort -rn|awk '{if (1>num){print2}}'`
do
iptables -I INPUT -p tcp -s $i --dport 22 -j DROP
done
最近要使用thinkphp3.2版本的cli模式,手动执的话没有问题,比如php /www/index.php home/article/get 这样没有问题,但是一般用cli模式都是定时任务比较多,这个时候写到定时任务的时候,比如 0 * php /www/index.php home/article/get 这样就会出现引入ThinkPHP.php失败的问题,这个问题算是比较容易解决的,但是后来还有其他各种报错,经过查看相关核心代码,终于找到无需修改代码,就可以轻易使用cli模式的方法。
步骤如下: 1、官方下载的框架文件里面的index.php文件引入其他文件使用的是相对路径,这导致了定时执行的时候引入ThinkPHP.php文件不存在的问题,修改成绝对路径即可。 define( ‘APP_PATH’, dirname(FILE).’/Application/’ ); require dirname( FILE).’/ThinkPHP/ThinkPHP.php’;
2、思维要倒回去第半步,刚刚说index.php文件的相对路径跟绝对路径的问题,但是执行cli模式的时候,我们的入口文件要有别于通过web服务访问的index.php文件,比如增加cli模式的入口文件cli.php,内容跟index.php的一样,同时增加一句话 define(‘APP_MODE’,’cli’); 定义APP的执行模式。此时,我们有两个入口文件,一个是web服务访问方式的index.php,另一个是cli模式访问的cli.php 3、在路径 /ThinkPHP/Mode 下面有个文件,名字叫做common.php ,复制一份出来,命名为cli.php,然后把里面引入日志类的代码注释或者删除掉 ‘Think\Log’ => CORE_PATH . ‘Log’.EXT,
4、删除缓存下面的所有缓存——记得是所有
5、再啰嗦一句,以后cli模式调用的时候,就用cli.php入口文件,比如定时任务 0 php /www/cli.php home/article/get ,如果是web服务访问,则依然使用index.php文件
原文出自 兴奋小猪 http://www.xingfenxiaozhu.com/2015/11/14/thinkphp-3-2的cli模式(命令行模式)的正确使用方法/ 转载请注明出处
安装composer中文镜像http://www.phpcomposer.com/,然后重启
{
"scripts": {
"post-install-cmd": [
"PhantomInstaller\\Installer::installPhantomJS"
],
"post-update-cmd": [
"PhantomInstaller\\Installer::installPhantomJS"
]
},
"config": {
"bin-dir": "bin"
},
"require": {
"jonnyw/php-phantomjs": "4.*"
}
}
进入项目文件夹运行下面的的命令即可 composer require “jonnyw/php-phantomjs:4.*”
getEngine()->setPath('E:/xampp/php/phantomjs.exe');
//上面一行要填写自己的phantomjs路径
/**
* @see JonnyW\PhantomJs\Http\PdfRequest
**/
delay = 7;request = client->getMessageFactory()->createPdfRequest('https://www.baidu.com/', 'GET', 5000); //参数里面的数字5000是网页加载的超时时间,放在网络问题一直加载,可以不填写,默认5s。request->setOutputFile('E:/document.pdf');
request->setFormat('A4');request->setOrientation('landscape');
request->setMargin('1cm');request->setDelay(delay);//设置delay是因为有一些特效会在页面加载完成后加载,没有等待就会漏掉
/** * @see JonnyW\PhantomJs\Http\Response **/response = client->getMessageFactory()->createResponse();
// Send the requestclient->send(request,response);
To obtain the code using Git from the official repository github.com/ariya/phantomjs:
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:
1.6 在终端下测试Phantomjs
注意系统目录为/usr/bin/ 至此成功
sudo apt-get install phantomjs
检查是否正常工作,输入以下命令:
phantomjs --version
若显示当前版本号,则 Phantomjs 安装成功。