本帖最后由 Dlan 于 2016-1-18 12:00 编辑
2016年1月18日 更新,添加了网络异常的判断
使用教程:
1.安装python http://jingyan.baidu.com/article/7908e85c78c743af491ad261.html
2.获取你的cookies:
获取后写入文件的your cookie 位置 注意 不要覆盖了引号
3.挂机:
centos: yum install screen
ubuntu: apt-get install screen
screen使用教程:http://www.cnblogs.com/mchina/archive/2013/01/30/2880680.html
源码:
[Python] 纯文本查看 复制代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import urllib2
import sys
import re
class WAPJ():
def __init__(self,cookies):
self.cookies = cookies
self.sign = 'http://www.52pojie.cn/home.php?mod=task&do=apply&id=2'
self.info1 = 'http://www.52pojie.cn/home.php?mod=spacecp&ac=usergroup&showextgroups=0&inajax=2&ajaxtarget=g_upmine_menu'
self.info2 = 'http://www.52pojie.cn/home.php?mod=spacecp&ac=credit&showcredit=0&inajax=1&ajaxtarget=extcreditmenu_menu'
# self.space = "http://www.52pojie.cn/home.php?mod=space&uid=159808&do=profile&from=space"
self.headers = {'user-agent':'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0',
'Cookie': self.cookies
}
def signAndOnLine(self):
try:
req = urllib2.Request(self.sign,headers=self.headers)
req2 = urllib2.Request(self.space,headers=self.headers)
res = urllib2.urlopen(req,timeout=4)
res2 = urllib2.urlopen(req2,timeout=4)
page = res.read()
page2 = res2.read()
except Exception, e :
print e
print '[-]Network anomaly '
return False
if 'LCG_Register' in page: #没有登陆成功
print '[-]Cookies is error! \n[-]Loging fail!'
sys.exit()
if 'task&item=new'in page:
print 'Refresh success!'
#m = re.search('</em>(.*?)</li><li><em>', page2)
# if m:
# print m.group(1)
return True
def getInfo(self):
pass
def run(self):
if self.signAndOnLine():
print '10 minutes to refresh'
while True:
self.signAndOnLine()
time.sleep(300)
if __name__ == '__main__':
wapj = WAPJ("")
wapj.run()
运行图例:
|