Last active
August 29, 2015 14:01
-
-
Save Yunanw/cb1eb9e6449a6fe78319 to your computer and use it in GitHub Desktop.
当年某宝刷钻平台抢任务代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() | |
################################################### | |
# 自动刷钻程序 | |
# | |
################################################### | |
#读配置 | |
InitConfig() | |
#登陆 | |
ret = Login() | |
while(ret): | |
taskListPage = OpenTaskListPage() | |
TaskList = AnlyseTaskListPage(taskListPage) | |
if len(TaskList) == 0: | |
print U'未找到合适任务' | |
for taskid in TaskList: | |
ProcessTaskAsync(taskid) | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment