Python_某宝某东秒杀抢购

纯学习分享,只用于学习用途,请勿用于任何商业用途。本人不承担任何责任。

视频编写过程:某宝秒杀程序

某宝源码: 

from selenium import webdriver
from selenium.webdriver.common.by import By
import datetime
import time

# 秒杀时间
target_time = "2022-10-14 20:00:00.00000000"

driver = webdriver.Chrome()
driver.get("https://login.taobao.com/member/login.jhtml")
time.sleep(3) # 等待登录界面
driver.find_element(By.CLASS_NAME,'icon-qrcode').click() # 点击二维码扫码界面
time.sleep(10) # 等待二维码扫码登录
driver.get('https://cart.taobao.com/cart.htm') # 进去购物车页面
time.sleep(2)

while True:
    try:
        # 是否点击全选购
        if driver.find_element(By.ID,'J_SelectAll1'):
            driver.find_element(By.ID,'J_SelectAll1').click()
            print('已勾选购买按钮!')
            break
    except:
        print('找不到购买按钮')

while True:
    # 当前时间
    current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
    print(current_time)
    # 当前时间>=秒杀时间
    if current_time >= target_time:
        while True:
            try:
                # 点击结算
                if driver.find_element(By.LINK_TEXT,'结 算'):
                    driver.find_element(By.LINK_TEXT,'结 算').click()
                    print("已锁定商品,结算成功!")
                    break
            except:
                pass
        while True:
            try:
                # 点击提交菜单
                if driver.find_element_by_link_text('提交订单'):
                    driver.find_element_by_link_text('提交订单').click()
                    print('抢购成功,请尽快付款!')
            except:
                print('已抢到商品,请及时付款')
                break
        time.sleep(0.01)


 

某东源码: 

# 导入浏览器自动化模块
from selenium import webdriver
import datetime
import time

# 秒杀时间
target_time = "2022-10-15 13:55:00.00000000"

# 打开浏览器驱动
driver = webdriver.Chrome()
# 获取网页
driver.get('https://passport.jd.com/new/login.aspx')
time.sleep(10) # 等待扫码登录
# 获取购物车网页
driver.get('https://cart.jd.com/cart_index')
time.sleep(3)
# 点击结算标签
while True:
    # 当前时间
    current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
    print(current_time)
    if current_time >=target_time:
        while True:
            try:
                if driver.find_element_by_class_name('btn-area'):
                    driver.find_element_by_class_name('btn-area').click()
                    print('已锁定商品,等待结算!')
                    break
            except:
                pass
        time.sleep(0.1)
        # 点击提交订单
        while True:
            try:
                if driver.find_element_by_id('order-submit'):
                    driver.find_element_by_id('order-submit').click()
                    print('抢购成功,请尽快付款!')
            except:
                break
        time.sleep(0.01)
#

你可能感兴趣的:(python,python,开发语言,chrome)