推荐【京东抢1499元 53度飞天茅台】 代码

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,需要使用Python来实现自动化购。 1. 导入必要的库和模块 ```python import time import selenium.webdriver as webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By ``` 2. 设置chrome浏览器并打开京东茅台的页面 ```python options = webdriver.ChromeOptions() options.add_argument('user-data-dir=C:\\Users\\{username}\\AppData\\Local\\Google\\Chrome\\User Data') # 将{username}替换为你的计算机用户名 browser = webdriver.Chrome(chrome_options=options) browser.get('https://item.jd.com/100012043978.html') ``` 3. 等待页面加载并定位购按钮,点击购按钮 ```python while True: try: timer = WebDriverWait(browser, 1).until(EC.presence_of_element_located((By.ID, 'btn-reservation'))) if timer.text == '立即预约': timer.click() elif timer.text == '已成功预约': print('已成功预约') break except: pass ``` 4. 等待预约成功页面加载,并定位到购按钮,点击购按钮 ```python while True: try: btn = WebDriverWait(browser, 1).until(EC.presence_of_element_located((By.ID, 'btn-reservation-attention'))) if btn.text == '提醒我': btn.click() elif btn.text == '已设置提醒': print('已设置提醒') break except: pass ``` 5. 等待购页面加载,并定位到购按钮,点击购按钮 ```python while True: try: btn = WebDriverWait(browser, 1).until(EC.presence_of_element_located((By.ID, 'btn-reservation-order'))) if btn.text == '立即购': btn.click() break elif btn.text == '已添加到购物车': print('已添加到购物车') break except: pass ``` 6. 等待购物车页面加载,并定位到提交订单按钮,点击提交订单按钮 ```python while True: try: btn = WebDriverWait(browser, 1).until(EC.presence_of_element_located((By.CLASS_NAME, 'submit-btn'))) if btn.text == '提交订单': btn.click() break except: pass ``` 7. 等待订单确认页面加载,并勾选同意协议,提交订单 ```python while True: try: input = WebDriverWait(browser, 1).until(EC.presence_of_element_located((By.ID, 'order-submit'))) if input.get_attribute('class') == 'submit-btn order-submit J_orderSubmit': agree = WebDriverWait(browser, 1).until(EC.presence_of_element_located((By.CLASS_NAME, 'payment-bd-agree'))) if not agree.is_selected(): agree.click() input.click() break except: pass ``` 完整代码如下: ```python import time import selenium.webdriver as webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By options = webdriver.ChromeOptions() options.add_argument('user-data-dir=C:\\Users\\{username}\\AppData\\Local\\Google\\Chrome\\User Data') # 将{username}替换为你的计算机用户名 browser = webdriver.Chrome(chrome_options=options) browser.get('https://item.jd.com/100012043978.html') while True: try: timer = WebDriverWait(browser, 1).until(EC.presence_of_element_located((By.ID, 'btn-reservation'))) if timer.text == '立即预约': timer.click() elif timer.text == '已成功预约': print('已成功预约') break except: pass while True: try: btn = WebDriverWait(browser, 1).until(EC.presence_of_element_located((By.ID, 'btn-reservation-attention'))) if btn.text == '提醒我': btn.click() elif btn.text == '已设置提醒': print('已设置提醒') break except: pass while True: try: btn = WebDriverWait(browser, 1).until(EC.presence_of_element_located((By.ID, 'btn-reservation-order'))) if btn.text == '立即购': btn.click() break elif btn.text == '已添加到购物车': print('已添加到购物车') break except: pass while True: try: btn = WebDriverWait(browser, 1).until(EC.presence_of_element_located((By.CLASS_NAME, 'submit-btn'))) if btn.text == '提交订单': btn.click() break except: pass while True: try: input = WebDriverWait(browser, 1).until(EC.presence_of_element_located((By.ID, 'order-submit'))) if input.get_attribute('class') == 'submit-btn order-submit J_orderSubmit': agree = WebDriverWait(browser, 1).until(EC.presence_of_element_located((By.CLASS_NAME, 'payment-bd-agree'))) if not agree.is_selected(): agree.click() input.click() break except: pass ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值