|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 cdzjf 于 2020-8-30 11:37 编辑
写的界面很简单,也有点low,也是第一个GUI界面的,程序需要手动输入cookie,暂时没有办法绕过京东登录的滑块验证,不知道用selenium方式让用户自己网页登录后获取cookie是否可行,毕竟用户的使用环境不一样。
程序有个自动调整京东时间的选项,所以运行需要管理员方式运行,大神有什么指点的,欢迎留言
import requests
import datetime
import time
import re
import set_time
import random
import json
import tkinter as tk
import tkinter
import set_time
import tkinter.messagebox
def timenow():
stime=datetime.datetime.now()
var.set(stime)
root.after(1, timenow)
root.update()
def settime():
set_time.settime()
tkinter.messagebox.showinfo(message="同步成功")
def co():
# 将输入的cookie保存到变量
global cookie
cookie = cook.get()
# 先清空一下文本框
t.delete('0.0', 'end')
verify(cookie)
root.update()
def verify(cookie):
url_name = 'https://wq.jd.com/user/info/QueryJDUserInfo?_=1595520976283&sceneval=2&g_login_type=1&callback=cbQueryJDUserInfo&g_tk=160746156&g_ty=ls'
head = {'Referer': 'https://wqs.jd.com/my/accountv2.shtml',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36 Maxthon/5.3.8.2000',
'cookie': cookie}
ree = requests.session()
response = ree.get(url_name, headers=head)
response.encoding = "utf-8"
response = response.text
temp = re.findall('"curPin" : ([\w\W]*?),[\w\W]*?"nickname" : ([\w\W]*?),', response)
name='用户名:%s,昵称:%s' % (temp[0][0], temp[0][1])
t.insert('end', name)
root.update()
def star():
scheduled=nowtime.get()
p.delete('0.0', 'end')
url22=url2.get()
# api地址
url = url22
head = {'Referer': 'https://a.jd.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36 Maxthon/5.3.8.2000',
'cookie': cookie}
s = requests.session()
# 获得系统时间并且截取其中的时分
hourse_temp = (str(datetime.datetime.now())[11:16])
now_hourse = hourse_temp[0:2] + hourse_temp[3:6]
# 把日期加1,目的是后面减1
aa = (str(datetime.datetime.now() + datetime.timedelta(days=1))[0:10])
y1 = aa[0:4]
m1 = aa[5:7]
d1 = aa[8:10]
# 拼接年月日时分秒
scheduled_time = y1 + m1 + d1 + scheduled + '00'
# 转字符串为日期格式,并且秒数减1,这样日期会自动减一天,才能正常
scheduled_time = datetime.datetime.strptime(scheduled_time, "%Y%m%d%H%M%S") + datetime.timedelta(seconds=0)
if scheduled > now_hourse:
d1 = int(d1) - 1
# 拼接年月日时分秒
scheduled_time = y1 + m1 + str(d1) + scheduled + '00'
scheduled_time = datetime.datetime.strptime(scheduled_time, "%Y%m%d%H%M%S") + datetime.timedelta(microseconds=0)
scTime = str(scheduled_time)
# 去掉时间中间的,只保留数字转整形
scTime = scTime[0:4] + scTime[5:7] + scTime[8:10] + scTime[11:13] + scTime[14:16] + scTime[17:19]
scheduled_time_int = int(scTime)
tx="将于%s开始自动抢劵" % scheduled_time
p.insert('end', tx)
p.insert('end', '\n')
a = 0
root.update()
while a == 0:
root.update()
ymdhms = datetime.datetime.now()
ymdhms = str(ymdhms)
nowtime_ymdhms = ymdhms[0:4] + ymdhms[5:7] + ymdhms[8:10] + ymdhms[11:13] + ymdhms[14:16] + ymdhms[17:19]
if scheduled_time_int <= int(nowtime_ymdhms):
start2 = time.time()
print("时间到")
# print("开始的时间是:%s" % datetime.datetime.now())
while True:
ran = random.random()
start = time.time()
print("抢劵时间是:%s" % datetime.datetime.now())
response = s.get(url, headers=head)
print("抢完劵时间是:%s" % datetime.datetime.now())
response.encoding = "utf-8"
response = response.text
print(response)
res_str = re.findall('"subCodeMsg":"([\w\W]*?)","', response)
res_str = str(res_str)
if res_str == '[]':
res_str = re.findall('"errmsg":"([\w\W]*?)","', response)
res_str = str(res_str)
if res_str == '[]':
res_str = re.findall('"desc":"([\w\W]*?)","', response)
res_str = str(res_str)
p.insert('end', res_str)
p.insert('end', '\n')
root.update()
if res_str.find(u"明日") != -1 or res_str.find(u"成功") != -1 or \
res_str.find(u'贪心') != -1 or res_str.find("not login") != -1 \
or res_str.find("擦肩而过") != -1 or res_str.find("不在活动时间内") != -1 \
or res_str.find("已抢完") != -1 or res_str.find("实名认证") != -1\
or res_str.find("来早了") != -1:
break
elif res_str.find(u"休息") != -1 or res_str.find("频繁") != -1 \
or res_str.find("火爆") != -1 or res_str.find("没抢到") != -1\
or res_str.find("稍后") != -1 or res_str.find("未登录") != -1:
time.sleep(ran)
print("延迟%f秒" % ran)
time.sleep(ran)
end = time.time()
# 判断如果时间已经过了,就停止了
if (end - start2) > 10:
break
a += 1
end2 = time.time()
a1="总耗时%.5f" % (end2 - start2)
a2="现在的时间是:%s" % datetime.datetime.now()
p.insert('end', a1)
p.insert('end', '\n')
p.insert('end', a2)
p.insert('end', '\n')
a3="Game Over~"
p.insert('end', a3)
if __name__=="__main__":
root = tk.Tk()
root.title("京东自动抢劵小程序")
# 最大化显示
root.state("zoomed")
tk.Label(root, text='Cookie:', font=('Arial', 15)).place(x=10, y=10, anchor='nw')
cook = tk.Entry(root, show=None, width=135, font=('Arial', 14))
cook.place(x=100, y=10)
bu = tk.Button(root, text="获取", width=10, height=2, command=co).place(x=30, y=100)
t = tk.Text(root, height=3, width=80)
t.place(x=160, y=100)
var = tkinter.StringVar()
jdtime = tk.Button(root, text="同步京东时间", width=10, height=2, command=settime).place(x=900, y=100)
# 时间显示
tk.Label(root, textvariable=var, font=('Arial', 15)).place(x=1140, y=110, anchor='nw')
tk.Label(root, text='当前时间:', font=('Arial', 15)).place(x=1015, y=110, anchor='nw')
tk.Label(root, text='开始时间:', font=('Arial', 15)).place(x=30, y=200, anchor='nw')
nowtime= tk.Entry(root, show=None, width=20, font=('Arial', 14))
tk.Label(root, text='请输入4位数字(如:0000,1400,1830等)', font=('Arial', 15)).place(x=350, y=200, anchor='nw')
nowtime.place(x=160, y=200)
tk.Label(root, text='抢劵地址:', font=('Arial', 15)).place(x=30, y=250, anchor='nw')
url2= tk.Entry(root, show=None, width=128, font=('Arial', 14))
url2.place(x=160, y=250)
star = tk.Button(root, text="开始抢劵", width=10, height=2, command=star).place(x=30, y=300)
p = tk.Text(root, height=30, width=185)
p.place(x=160, y=300)
timenow()
root.mainloop()
|
|