#
coding=utf-8
'''
Created on 2011-7-1
@author: Yunanw
'''
import cookielib, urllib2, urllib
import time
import lxml.html as H
import lxml.etree
import ConfigParser
from socket import *
import struct
# ===============================================================================
# 此处必改
# ===============================================================================
BuildTime = time.strptime( ' 2011-07-08 ' , " %Y-%m-%d " )
Payed = False
# ===============================================================================
# 常量
# ===============================================================================
CurrentTime = time.strptime( ' 1970-07-08 ' , " %Y-%m-%d " )
Password = ""
XiaoHao = ""
OpCode = ""
TaskPage = " http://www.shuazuanla.com/taobao.asp?flag=0 "
TimeServer = " time.apple.com "
# 初始化UrlLib模块
cookiejar = cookielib.CookieJar()
proxy = urllib2.ProxyHandler({ ' http ' : ' 127.0.0.1:8888 ' })
urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
urllib2.install_opener(urlOpener)
def Log(msg):
print msg
def Post(url, Data):
request = urllib2.Request(url, urllib.urlencode(Data))
page = urlOpener.open(request)
return page.read()
def Get(url):
request = urllib2.Request(url)
page = urlOpener.open(request)
return page.read()
def InitConfig():
config = ConfigParser.ConfigParser()
config.read( " config.ini " )
# #
global Password
Password = config.get( " userdata " , " password " )
global XiaoHao
XiaoHao = config.get( " userdata " , " xiaohao " )
global OpCode
OpCode = config.get( " userdata " , " opcode " )
global TaskPage
TaskPage = config.get( " userdata " , " taskpage " )
def Login():
# #登陆URL
loginUrl = " http://www.shuazuanla.com/user_log.asp "
usrAndPwd = { " UserName " : " 你的用户名 " , " PassWord " :Password}
ret = Post(loginUrl, usrAndPwd)
ret = ret.decode( ' gbk ' ).encode( ' utf-8 ' )
if ret.find( ' 用户名或密码错误 ' ) > - 1 :
print U ' 用户名或密码错误 '
return False
else :
return True
def OpenTaskListPage():
return Get(TaskPage)
# return Get("http://www.shuazuanla.com/taobao.asp")
def AnlyseTaskListPage(taskListPage):
# 开始分析
doc = H.document_fromstring(taskListPage)
trTaskList = doc.xpath( " //table[@style='background:url(images/fenlei_right.jpg) no-repeat;']//table[last()]/tr[position()>1] " )
taskList = []
for trTask in trTaskList:
tdTaskState = trTask.findtext( ' ./td[last()]/a ' )
if tdTaskState == U ' 等待接手 ' :
taskList.append(trTask.findtext( ' ./td[1]/a ' ))
return taskList
def ProcessTask(taskID):
print U " 找到任务: " + taskID
# ret = submitTask(taskID)
# print ret.split('<script>')[2]
def ProcessTaskAsync(taskID):
return ProcessTask(taskID)
def submitTask(taskID):
url = ' http://www.shuazuanla.com/showinfo.asp?action=sbuto&din= ' + taskID
postData = ' xiaohao=&xiaohao=&txiaohao_u842= ' + XiaoHao + ' &select=&opPassWord= ' + OpCode + ' &Submit=%C1%A2%BC%B4%BD%D3%CA%D6%C8%CE%CE%F1 '
request = urllib2.Request(url, postData)
# 网站会校验Refrer
request.add_unredirected_header( " Referer " , ' http://www.shuazuanla.com/showinfo.asp?action=jie&din= ' + taskID)
page = urlOpener.open(request)
return page.read()
def GetNetTime():
if Payed:
return None
time_server = (TimeServer, 123 )
TIME1970 = 2208988800L
client = socket(AF_INET, SOCK_DGRAM)
data = ' \x1b ' + 47 * ' \0 '
client.sendto(data, time_server)
data, address = client.recvfrom( 1024 )
if data:
t = struct.unpack( ' !12I ' , data)[ 10 ]
if t == 0:
raise U ' 取得时间出错 '
global CurrentTime
CurrentTime = time.localtime(t - TIME1970)
else :
raise U ' 与时间服务器通信失败 '
def TimeJudge():
if Payed:
return True
seconds = time.mktime(BuildTime) - time.mktime(CurrentTime)
print seconds
if seconds < 0:
raise U " 试用已到期,请付款 "
# ##################################################
# 自动刷钻程序
#
# ##################################################
GetNetTime()
# 读配置
InitConfig()
# 登陆
ret = Login()
while (ret):
taskListPage = OpenTaskListPage()
TaskList = AnlyseTaskListPage(taskListPage)
if len(TaskList) == 0:
print U ' 未找到合适任务 '
for taskid in TaskList:
ProcessTaskAsync(taskid)
TimeJudge()
time.sleep( 2 )
'''
Created on 2011-7-1
@author: Yunanw
'''
import cookielib, urllib2, urllib
import time
import lxml.html as H
import lxml.etree
import ConfigParser
from socket import *
import struct
# ===============================================================================
# 此处必改
# ===============================================================================
BuildTime = time.strptime( ' 2011-07-08 ' , " %Y-%m-%d " )
Payed = False
# ===============================================================================
# 常量
# ===============================================================================
CurrentTime = time.strptime( ' 1970-07-08 ' , " %Y-%m-%d " )
Password = ""
XiaoHao = ""
OpCode = ""
TaskPage = " http://www.shuazuanla.com/taobao.asp?flag=0 "
TimeServer = " time.apple.com "
# 初始化UrlLib模块
cookiejar = cookielib.CookieJar()
proxy = urllib2.ProxyHandler({ ' http ' : ' 127.0.0.1:8888 ' })
urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
urllib2.install_opener(urlOpener)
def Log(msg):
print msg
def Post(url, Data):
request = urllib2.Request(url, urllib.urlencode(Data))
page = urlOpener.open(request)
return page.read()
def Get(url):
request = urllib2.Request(url)
page = urlOpener.open(request)
return page.read()
def InitConfig():
config = ConfigParser.ConfigParser()
config.read( " config.ini " )
# #
global Password
Password = config.get( " userdata " , " password " )
global XiaoHao
XiaoHao = config.get( " userdata " , " xiaohao " )
global OpCode
OpCode = config.get( " userdata " , " opcode " )
global TaskPage
TaskPage = config.get( " userdata " , " taskpage " )
def Login():
# #登陆URL
loginUrl = " http://www.shuazuanla.com/user_log.asp "
usrAndPwd = { " UserName " : " 你的用户名 " , " PassWord " :Password}
ret = Post(loginUrl, usrAndPwd)
ret = ret.decode( ' gbk ' ).encode( ' utf-8 ' )
if ret.find( ' 用户名或密码错误 ' ) > - 1 :
print U ' 用户名或密码错误 '
return False
else :
return True
def OpenTaskListPage():
return Get(TaskPage)
# return Get("http://www.shuazuanla.com/taobao.asp")
def AnlyseTaskListPage(taskListPage):
# 开始分析
doc = H.document_fromstring(taskListPage)
trTaskList = doc.xpath( " //table[@style='background:url(images/fenlei_right.jpg) no-repeat;']//table[last()]/tr[position()>1] " )
taskList = []
for trTask in trTaskList:
tdTaskState = trTask.findtext( ' ./td[last()]/a ' )
if tdTaskState == U ' 等待接手 ' :
taskList.append(trTask.findtext( ' ./td[1]/a ' ))
return taskList
def ProcessTask(taskID):
print U " 找到任务: " + taskID
# ret = submitTask(taskID)
# print ret.split('<script>')[2]
def ProcessTaskAsync(taskID):
return ProcessTask(taskID)
def submitTask(taskID):
url = ' http://www.shuazuanla.com/showinfo.asp?action=sbuto&din= ' + taskID
postData = ' xiaohao=&xiaohao=&txiaohao_u842= ' + XiaoHao + ' &select=&opPassWord= ' + OpCode + ' &Submit=%C1%A2%BC%B4%BD%D3%CA%D6%C8%CE%CE%F1 '
request = urllib2.Request(url, postData)
# 网站会校验Refrer
request.add_unredirected_header( " Referer " , ' http://www.shuazuanla.com/showinfo.asp?action=jie&din= ' + taskID)
page = urlOpener.open(request)
return page.read()
def GetNetTime():
if Payed:
return None
time_server = (TimeServer, 123 )
TIME1970 = 2208988800L
client = socket(AF_INET, SOCK_DGRAM)
data = ' \x1b ' + 47 * ' \0 '
client.sendto(data, time_server)
data, address = client.recvfrom( 1024 )
if data:
t = struct.unpack( ' !12I ' , data)[ 10 ]
if t == 0:
raise U ' 取得时间出错 '
global CurrentTime
CurrentTime = time.localtime(t - TIME1970)
else :
raise U ' 与时间服务器通信失败 '
def TimeJudge():
if Payed:
return True
seconds = time.mktime(BuildTime) - time.mktime(CurrentTime)
print seconds
if seconds < 0:
raise U " 试用已到期,请付款 "
# ##################################################
# 自动刷钻程序
#
# ##################################################
GetNetTime()
# 读配置
InitConfig()
# 登陆
ret = Login()
while (ret):
taskListPage = OpenTaskListPage()
TaskList = AnlyseTaskListPage(taskListPage)
if len(TaskList) == 0:
print U ' 未找到合适任务 '
for taskid in TaskList:
ProcessTaskAsync(taskid)
TimeJudge()
time.sleep( 2 )