腾讯云
关注微信公众号: 生活服务一站达,不定期更新更新黑科技、脚本等资源
准备软件
下载地址 : https://download.csdn.net/download/tangcv/11968538
pycharm文件太大,不好上传 ,直接去官网下载:https://www.jetbrains.com/pycharm/download/#section=windows
配置环境
1.安装python
双击
然后跟着感觉走,
创建一个专门的文件夹用来放python环境
安装好
2..安装pycharm
1、首先去Pycharm官网,或者直接输入网址:http://www.jetbrains.com/pycharm/download/#section=windows,下载PyCharm安装包,根据自己电脑的操作系统进行选择,对于windows系统选择下图的框框所包含的安装包。
破解涉嫌版权问题,请自行解决
3.安装火狐浏览器、火狐浏览器安装FireBug插件
火狐浏览器
双击 Firefox-latest 安装 火狐浏览器
FireBug插件
右上角 附加组件 > 扩展 > 搜索 FireBug
选择 Omnibug 安装
按F12 出现下图 ,安装成功
4.geckodriver 驱动安装
1.解压geckodriver-v0.26.0-win64
2.将 geckodriver 放到 该浏览器可执行文件的路径下
3.添加到环境变量中
4.将 geckodriver 放到 该python可执行文件的路径下
测试配置是否完成
用pycharm创建一个python项目
File > Settings > project: ms > project interpreter
添加selectninm 和 urlib3
新建一个python文件
-
# -*- coding: utf-8 -*-
-
from selenium
import webdriver
-
driver = webdriver.Firefox()
-
driver.get(
"https://www.baidu.com")
右键 执行
浏览器自动打开 进入百度
完成配置
淘宝秒杀程序
二维码登录
-
#!/usr/bin/env python
-
# -*- coding: utf-8 -*-
-
# 2018/09/05
-
# 淘宝秒杀脚本,扫码登录版
-
import os
-
from selenium
import webdriver
-
import datetime
-
import time
-
from os
import path
-
from selenium.webdriver.common.action_chains
import ActionChains
-
-
d = path.dirname(__file__)
-
abspath = path.abspath(d)
-
-
driver = webdriver.Firefox()
-
driver.maximize_window()
-
-
-
def login():
-
# 打开淘宝登录页,并进行扫码登录
-
driver.get(
"https://www.taobao.com")
-
time.sleep(
3)
-
if driver.find_element_by_link_text(
"亲,请登录"):
-
driver.find_element_by_link_text(
"亲,请登录").click()
-
-
print(
"请在30秒内完成扫码")
-
time.sleep(
30)
-
-
driver.get(
"https://cart.taobao.com/cart.htm")
-
time.sleep(
3)
-
# 点击购物车里全选按钮
-
# if driver.find_element_by_id("J_CheckBox_939775250537"):
-
# driver.find_element_by_id("J_CheckBox_939775250537").click()
-
# if driver.find_element_by_id("J_CheckBox_939558169627"):
-
# driver.find_element_by_id("J_CheckBox_939558169627").click()
-
if driver.find_element_by_id(
"J_SelectAll1"):
-
driver.find_element_by_id(
"J_SelectAll1").click()
-
now = datetime.datetime.now()
-
print(
'login success:', now.strftime(
'%Y-%m-%d %H:%M:%S:%f'))
-
-
-
def buy(buytime):
-
while
True:
-
now = datetime.datetime.now().strftime(
'%Y-%m-%d %H:%M:%S.%f')
-
print(
"当前时间" + now)
-
# 对比时间,时间到的话就点击结算
-
if now > buytime:
-
try:
-
# 点击结算按钮
-
if driver.find_element_by_id(
"J_Go"):
-
driver.find_element_by_id(
"J_Go").click()
-
driver.find_element_by_link_text(
'提交订单').click()
-
except:
-
time.sleep(
0.1)
-
print(now)
-
time.sleep(
0.1)
-
-
-
if __name__ ==
"__main__":
-
# times = input("请输入抢购时间:")
-
# 时间格式:"2018-09-06 11:20:00.000000"
-
login()
-
buy(
"2019-11-10 01:14:00.000000")
账号密码登录
-
#!/usr/bin/env python
-
# -*- coding: utf-8 -*-
-
# 2018/09/05
-
# 淘宝秒杀脚本,扫码登录版
-
import os
-
from selenium
import webdriver
-
import datetime
-
import time
-
from os
import path
-
from selenium.webdriver.common.action_chains
import ActionChains
-
-
d = path.dirname(__file__)
-
abspath = path.abspath(d)
-
-
driver = webdriver.Firefox()
-
driver.maximize_window()
-
-
-
def login(uname, pwd):
-
driver.get(
"https://www.taobao.com")
-
if driver.find_element_by_link_text(
"亲,请登录"):
-
driver.find_element_by_link_text(
"亲,请登录").click()
-
input(uname, pwd)
-
-
# 点击购物车里全选按钮
-
if driver.find_element_by_id(
"J_SelectAll1"):
-
driver.find_element_by_id(
"J_SelectAll1").click()
-
# time.sleep(3)
-
now = datetime.datetime.now()
-
print(
'login success:', now.strftime(
'%Y-%m-%d %H:%M:%S'))
-
-
-
def input(uname, pwd):
-
time.sleep(
3)
-
# 选择密码登录
-
if driver.find_element_by_id(
"J_Quick2Static"):
-
driver.find_element_by_id(
"J_Quick2Static").click()
-
time.sleep(
3)
-
-
# 用户名输入
-
if driver.find_element_by_name(
"TPL_username"):
-
for i
in uname:
-
driver.find_element_by_name(
"TPL_username").send_keys(i)
-
time.sleep(
0.5)
-
time.sleep(
3)
-
-
# 密码输入
-
if driver.find_element_by_name(
"TPL_password"):
-
for j
in pwd:
-
driver.find_element_by_name(
"TPL_password").send_keys(j)
-
time.sleep(
0.5)
-
time.sleep(
3)
-
-
# 点击登录按钮
-
if driver.find_element_by_id(
"J_SubmitStatic"):
-
driver.find_element_by_id(
"J_SubmitStatic").click()
-
time.sleep(
3)
-
driver.get(
"https://cart.taobao.com/cart.htm")
-
time.sleep(
2)
-
-
-
def buy(buytime):
-
while
True:
-
now = datetime.datetime.now().strftime(
'%Y-%m-%d %H:%M:%S')
-
if now == buytime:
-
try:
-
# 点击结算按钮
-
if driver.find_element_by_id(
"J_Go"):
-
driver.find_element_by_id(
"J_Go").click()
-
driver.find_element_by_link_text(
'提交订单').click()
-
except:
-
time.sleep(
1)
-
print(now)
-
time.sleep(
1)
-
-
-
if __name__ ==
"__main__":
-
# 中文账号记得decode编码
-
login(
"账号",
'密码')
-
buy(
'2019-11-10 01:01:01.000001')
腾讯云
阿里云
转载:https://blog.csdn.net/tangcv/article/details/102994075
查看评论