淘宝自动抢购脚本「建议收藏」

您所在的位置:网站首页 写个抢购脚本得多少钱 淘宝自动抢购脚本「建议收藏」

淘宝自动抢购脚本「建议收藏」

2024-02-21 13:40| 来源: 网络整理| 查看: 265

大家好,又见面了,我是你们的朋友全栈君。

淘宝自动抢购脚本抢购脚本是通过Selenium来完成自动登录,和自动点击的操作的。Selenium是一个用于Web应用程序测试的工具,Selenium可以直接运行在浏览器中,通过后台控制操作浏览器,完成购买操作。教程

需要安装python环境,安装python环境可参考链接 安装python完后记得配置环境和安装Pycharm编辑器(安装Pycharm可参考)

一、安装Selenium库

Selenium模块是Python的第三方库,可以通过pip进行安装:

pip3 install selenium

二、下载chromedriver.exe

下载和Chrome浏览器对应版本的chromedriver.exe

三、代码解释需要加载一些库import os from selenium import webdriver import datetime import time from os import path driver = webdriver.Chrome()登录淘宝的函数代码def login(url): # 打开淘宝登录页,并进行扫码登录 driver.get("https://www.taobao.com") time.sleep(3) if driver.find_element_by_link_text("亲,请登录"): driver.find_element_by_link_text("亲,请登录").click() print("请在10秒内完成扫码") time.sleep(5) driver.get(url) time.sleep(3) now = datetime.datetime.now() print('login success:', now.strftime('%Y-%m-%d %H:%M:%S'))抢购商品的函数代码def buy(buytime): while True: now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') # 对比时间,时间到的话就点击结算 if now >= buytime: try: # 点击抢购 if driver.find_element_by_id("J_LinkBuy"): print("速度点击!!!") driver.find_element_by_id("J_LinkBuy").click() time.sleep(0.09) while now >= buytime: try: print("赶紧买!!!") driver.find_element_by_class_name('go-btn').click() driver.find_element_by_link_text('提交订单').click() except: time.sleep(0.02) except: time.sleep(0.08) print(now) time.sleep(0.05)程序运行主函数代码if __name__ == "__main__": times = input("请输入抢购时间:时间格式:2021-12-29 19:45:00.000000") # 时间格式:"2022-03-19 11:43:00.000000" # 测试可以 # https://detail.tmall.com/item.htm?spm=a230r.1.14.16.6a903f34xN9uol&id=618488552961&ns=1&abbucket=12&skuId=4988554791826 url = input("请输入抢购地址") login(url) buy(times)四、本教程中所有代码# 淘宝秒杀脚本,扫码登录版 import os from selenium import webdriver import datetime import time from os import path driver = webdriver.Chrome() def login(url): # 打开淘宝登录页,并进行扫码登录 driver.get("https://www.taobao.com") time.sleep(3) if driver.find_element_by_link_text("亲,请登录"): driver.find_element_by_link_text("亲,请登录").click() print("请在10秒内完成扫码") time.sleep(5) driver.get(url) time.sleep(3) now = datetime.datetime.now() print('login success:', now.strftime('%Y-%m-%d %H:%M:%S')) def buy(buytime): while True: now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') # 对比时间,时间到的话就点击结算 if now >= buytime: try: # 点击抢购 if driver.find_element_by_id("J_LinkBuy"): print("速度点击!!!") driver.find_element_by_id("J_LinkBuy").click() time.sleep(0.09) while now >= buytime: try: print("赶紧买!!!") driver.find_element_by_class_name('go-btn').click() driver.find_element_by_link_text('提交订单').click() except: time.sleep(0.02) except: time.sleep(0.08) print(now) time.sleep(0.05) if __name__ == "__main__": times = input("请输入抢购时间:时间格式:2021-12-29 19:45:00.000000") # 时间格式:"2022-03-19 11:43:00.000000" # 测试可以 # https://detail.tmall.com/item.htm?spm=a230r.1.14.16.6a903f34xN9uol&id=618488552961&ns=1&abbucket=12&skuId=4988554791826 url = input("请输入抢购地址") login(url) buy(times)五、抢购脚本效果1 启动程序,Chrome浏览器会弹出页面 在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述2 输入抢购时间 和 商品链接 在这里插入图片描述在这里插入图片描述3 Chrome浏览器弹出淘宝登录页面 在这里插入图片描述在这里插入图片描述4 淘宝扫码登录 在这里插入图片描述在这里插入图片描述5 浏览器跳转到要抢购的商品页面 此时也可以点击选择其他商品 在这里插入图片描述在这里插入图片描述6 到达抢购时间后自动下单,输入支付密码即可 六、总结本次淘宝抢购脚本只是一个抢购功能的小演示,实际上淘宝的双十一的抢购需要对商品的抢购页面前端购买按钮未到抢购时间是不开放的,后台也需要针对具体的抢购业务进行调整。本次抢购脚本不做抢购失败的处理。欢迎大家按照教程动手实现一下,感受一下。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/131542.html原文链接:https://javaforall.cn



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3