Python实现京东秒杀功能代码
作者:SunChao3555 时间:2021-08-14 15:41:27
本文实例为大家分享了Python实现京东秒杀功能的具体代码,供大家参考,具体内容如下
#Python 3.5
#coding:utf-8
#import scrapy
from selenium import webdriver
import time
import datetime
driver = webdriver.Firefox()
driver.get('https:www.jd.com/')
class JDLOGIN(object):
def login_jd(self,num,pwd):
driver.find_element_by_link_text('你好,请登录').click()
time.sleep(10)
driver.find_element_by_link_text('账户登录').click()
time.sleep(3)
driver.find_element_by_id('loginname').send_keys(num)
driver.find_element_by_id('nloginpwd').send_keys(pwd)
time.sleep(3)
driver.find_element_by_id('loginsubmit').click()
time.sleep(5)
nowwhandle = driver.current_window_handle
driver.find_element_by_link_text('我的购物车').click()
allhandles = driver.window_handles
for handle in allhandles:
if handle != nowwhandle:
driver.switch_to_window(handle)#切换至窗口 购物车页面
time.sleep(5)
driver.find_element_by_link_text('去结算').click()
time.sleep(4)
def buy_on_time(self,buytime):
while True:
now = datetime.datetime.now()
if now.strftime('%Y-%m-%d %H:%M:%S') == buytime:
driver.find_element_by_id('order-submit').click()
time.sleep(3)
print(now.strftime('%Y-%m-%d %H:%M:%S'))
print('successful!!!')
time.sleep(0.5)
# 返回原先到的窗口
#driver.switch_to_window(nowwhandle)
def start(self,num,pwd,buytime):
self.login_jd(num,pwd)
self.buy_on_time(buytime)
jdlogin=JDLOGIN()
jdlogin.start('手机号','密码','秒杀时间' )
需要先将秒杀物品添加至购物车(必须为秒杀物品,秒杀无品加入购物车后结算时不需要勾选【全选框】),并提前设置默认收货地址
该代码为闲时所写,没有进一步优化,面向对象的函数也不够精简,不过功能已经实现
需要在cmd命令行安装selenium包:pip install selenium
其余包同理,需要啥下载即可
以上所述是小编给大家介绍的Python实现京东秒杀功能详解整合网站的支持!
来源:https://blog.csdn.net/SunChao3555/article/details/79143858
标签:Python,京东,秒杀
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JavaScript中的"类" 序言
2008-02-18 13:26:00
python3中rank函数的用法
2022-09-26 07:00:45
ASP写的不错的"数字分页"涵数
2008-10-19 17:21:00
go如何利用orm简单实现接口分布式锁
2023-06-17 16:55:04
TensorFlow实现简单线性回归
2023-09-18 13:23:45
![](https://img.aspxhome.com/file/2023/9/92519_0s.jpg)
python烟花效果的代码实例
2022-09-01 05:42:41
![](https://img.aspxhome.com/file/2023/6/89096_0s.gif)
利用Python复制文件的9种方法总结
2022-06-25 15:00:27
![](https://img.aspxhome.com/file/2023/6/70656_0s.png)
基于Python实现自动化文档整理工具
2021-10-01 01:29:19
![](https://img.aspxhome.com/file/2023/7/120337_0s.png)
javabean servlet jsp实现分页功能代码解析
2023-06-13 15:21:24
![](https://img.aspxhome.com/file/2023/2/63032_0s.png)
python Pexpect模块的使用
2023-01-23 20:54:58
python3 pathlib库Path类方法总结
2022-06-10 18:38:11
python使用Flask框架获取用户IP地址的方法
2023-08-09 03:15:23
Python中音频处理库pydub的使用教程
2023-07-15 20:22:54
python 读写文件包含多种编码格式的解决方式
2022-01-12 18:02:10
960 时代的终结
2011-01-11 19:24:00
![](https://img.aspxhome.com/file/UploadPic/20111/11/1294635311-31s.png)
一小时学会TensorFlow2之Fashion Mnist
2023-01-27 12:08:16
![](https://img.aspxhome.com/file/2023/2/85132_0s.jpg)
Python深度学习线性代数示例详解
2022-06-03 23:52:14
![](https://img.aspxhome.com/file/2023/8/91828_0s.png)
javascript彩虹圈效果
2011-08-05 19:10:45
Python递归实现打印多重列表代码
2023-05-28 10:38:32
Python中asyncore异步模块的用法及实现httpclient的实例
2021-02-19 01:05:18