淘宝自动化下单脚本
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from gettime import tbtime # 获取淘宝时间戳
'''以下两行代码解决支付宝支付页面对webdriver的检测'''
options = webdriver.ChromeOptions()
options.add_argument("disable-blink-features=AutomationControlled")
class TcBao(object): # 创建类
def __init__(self):
self.buy_time = 1686830400 #购买时间戳
self.browser = webdriver.Chrome(options=options) #过检测
self.diff_jiesuan = -5 #点击结算按钮时间差
self.diff_tijiao = 0.05 # 提交订单时间差
def get_login(self):
self.browser.get("https://www.taobao.com")
time.sleep(2)
self.browser.find_element(By.LINK_TEXT, "亲,请登录").click()
print(f"请尽快扫码登录")
def refresh(self):
self.browser.get("https://cart.taobao.com/cart.htm")
while True:
if self.buy_time - tbtime.get_time() > 80: # 现在时间与购买时间相差大于80秒就刷新购物车
self.browser.get("https://cart.taobao.com/cart.htm")
time.sleep(50)
else:
print("抢购时间点将近,停止刷新,准备抢购...")
break
def get_cart_all(self):
while True:
try:
if self.browser.find_element(By.ID, "J_SelectAll1"):
self.browser.find_element(By.ID, "J_SelectAll1").click()
print("已经选中全部商品")
break
except:
print("未点击购物车全选")
def settlement(self):
while True:
if tbtime.get_time() - self.buy_time >= self.diff_jiesuan:
try:
self.browser.find_element(By.LINK_TEXT, "结 算").click()
self.time_jiesuan = tbtime.get_time()
print("结算点击成功")
break
except:
None
def submit(self):
while True:
if tbtime.get_time() - self.buy_time >= self.diff_tijiao:
try:
self.browser.find_element(By.LINK_TEXT, '提交订单').click()
self.time_tijiao = tbtime.get_time()
print("订单提交成功")
break
except:
None
def run(self):
self.get_login()
while True:
Ok = int(input('登录完成后请输入1:'))
if Ok == 1:
self.refresh()
self.get_cart_all()
self.settlement()
self.submit()
print(self.time_jiesuan)
print(self.time_tijiao)
break
input("按任意键退出")
if __name__ == '__main__':
tb = TcBao()
tb.run()
while True:
print('def get_login1:')
print('refresh2')
print('get_cart_all3')
print('settlement4')
print('submit5')
n = int(input('input number:'))
if n == 1:
tb.get_login()
if n == 2:
tb.refresh()
if n == 3:
tb.get_cart_all()
if n == 4:
tb.settlement()
print(tb.time_jiesuan)
if n == 5:
tb.submit()
print(tb.time_tijiao)
-
- 其中使用的tbtime包
# -*- coding:utf-8 -*-
# 获取淘宝时间戳
import json
import time
import requests
url1 = 'http://acs.m.taobao.com/gw/mtop.common.getTimestamp/'
url2 = 'http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.43'
}
def get_time():
get_data = requests.get(url1, headers=headers)
data = json.loads(get_data.text)
time0 = data['data']['t']
time_1=time0[:10]+"."+time0[10:]
time_2=float(time_1)
#time_tb=time.strftime("%H %M %S", time.localtime(time_2))
return time_2
if __name__ == '__main__':
a=get_time()
print(a)
支付页面使用了iframe无法定位密码输入框文章来源地址https://www.toymoban.com/news/detail-765764.html
-
- 配合AHK输入支付密码
CoordMode, mouse
F1::
click 100 538
send 0
send 0
send 0
send 0
send 0
send 0
click 110,612
MsgBox, 1, Click Pay , %A_Hour%:%A_Min%:%A_Sec% , 2147483 ;弹出完成时间的窗口
文章来源:https://www.toymoban.com/news/detail-765764.html
到了这里,关于python-selenium淘宝自动化购买的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!