脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python实现京东秒杀功能

python实现京东秒杀功能

2021-03-24 00:20Erick-LONG Python

这篇文章主要为大家详细介绍了python实现京东秒杀功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了python实现京东秒杀的具体代码,供大家参考,具体内容如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# _*_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("https://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')

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://www.cnblogs.com/Erick-L/p/7391034.html

延伸 · 阅读

精彩推荐