Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > Python编程技巧

python实现京东秒杀功能

来源:中文源码网    浏览:1529 次    日期:2024-04-26 09:18:19
【下载文档:  python实现京东秒杀功能.txt 】


python实现京东秒杀功能
本文实例为大家分享了python实现京东秒杀的具体代码,供大家参考,具体内容如下
# _*_coding:utf-8_*_
from selenium import webdriver
import datetime
import time
driver = webdriver.Chrome(executable_path='chromedriver.exe')
def login(uname, pwd):
driver.get("http://www.jd.com")
driver.find_element_by_link_text("你好,请登录").click()
driver.find_element_by_link_text("账户登录").click()
driver.find_element_by_name("loginname").send_keys(uname)
driver.find_element_by_name("nloginpwd").send_keys(pwd)
driver.find_element_by_id("loginsubmit").click()
driver.get("http://cart.jd.com/cart.action")
driver.find_element_by_link_text("去结算").click()
now = datetime.datetime.now()
print('login success:',now.strftime('%Y-%m-%d %H:%M:%S'))
# buytime = '2016-12-27 22:31:00'
def buy_on_time(buytime):
while True:
now = datetime.datetime.now()
if now.strftime('%Y-%m-%d %H:%M:%S') == buytime:
while True:
try:
driver.find_element_by_id('order-submit').click()
except Exception as e:
time.sleep(0.1)
print ('purchase success',now.strftime('%Y-%m-%d %H:%M:%S'))
time.sleep(0.5)
# entrance
login('username', 'password')
buy_on_time('2017-01-01 14:00:01')
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持中文源码网。

相关内容