淘寶雙十一秒殺系統(tǒng)(可提前加入購物車)
# _*_coding:utf-8_*_
from selenium import webdriver
import datetime
import time
driver = webdriver.Firefox()
def login(uname, pwd):
driver.get("https://www.taobao.com/")
driver.find_element_by_link_text("親镐捧,請登錄").click()
driver.find_element_by_link_text("密碼登錄").click()
driver.find_element_by_name("TPL_username").send_keys(uname)
driver.find_element_by_name("TPL_password").send_keys(pwd)
driver.find_element_by_id("J_SubmitStatic").click()
time.sleep(3)
driver.get("https://cart.taobao.com/")
time.sleep(3)
driver.find_element_by_xpath('//input[@name="select-all"]').click() # click
driver.find_element_by_link_text("結 算").click()
now = datetime.datetime.now()
print now.strftime('%Y-%m-%d %H:%M:%S')
print 'login success'
# 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:
driver.find_element_by_class_name('go-btn').click()
time.sleep(3)
print now.strftime('%Y-%m-%d %H:%M:%S')
print 'purchase success'
time.sleep(0.5)
# entrance
login('username', 'code')
buy_on_time('2017-07-11 19:37:00')
淘寶聚劃算系統(tǒng)(不可提前得到秒殺地址)
# _*_coding:utf-8_*_
from selenium import webdriver
import datetime
import time
driver = webdriver.Firefox()
def login(uname, pwd):
driver.get("https://www.taobao.com/")
driver.find_element_by_link_text("親潜索,請登錄").click()
driver.find_element_by_link_text("密碼登錄").click() driver.find_element_by_name("TPL_username").send_keys(uname)
driver.find_element_by_name("TPL_password").send_keys(pwd)
driver.find_element_by_id("J_SubmitStatic").click()
time.sleep(3)
now = datetime.datetime.now()
print now.strftime('%Y-%m-%d %H:%M:%S')
print 'login success'
# 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:
#時間到,開始get界面
driver.get("https://detail.ju.taobao.com/home.htm?spm=608.2291429.102212b.1.24817b560Bv0M9&id=10000052045940&item_id=27089572187")
# 聚劃算界面
time.sleep(2)
driver.find_element_by_class_name("piclink").click()
driver.switch_to.window(driver.window_handles[1])
driver.find_element_by_class_name("J_LinkBuy").click()
time.sleep(2)
driver.find_element_by_class_name('go-btn').click()
print now.strftime('%Y-%m-%d %H:%M:%S')
print 'purchase success'
time.sleep(0.5)
# entrance
login('username', 'code')
buy_on_time('2017-07-11 19:37:00')
京東秒殺系統(tǒng)
# _*_coding:utf-8_*_
from selenium import webdriver
import datetime
import time
driver = webdriver.Firefox()
def login(uname, pwd):
driver.get("http://www.jd.com")
driver.find_element_by_link_text("你好懂酱,請登錄").click()
time.sleep(3)
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()
time.sleep(3)
driver.get("https://cart.jd.com/cart.action")
time.sleep(3)
#購物車中只有一件商品時才會自動勾選
driver.find_element_by_link_text("去結算").click()
now = datetime.datetime.now()
print now.strftime('%Y-%m-%d %H:%M:%S')
print 'login success'
def buy_on_time(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 'purchase success'
time.sleep(0.5)
# entrance
login('username', 'code')
buy_on_time('2017-07-11 16:01:00')
街道口職業(yè)技術學院圖書館搶座系統(tǒng)
需要安裝OCR環(huán)境http://www.reibang.com/p/19c82f64cd60
# -*- coding: utf-8 -*-
from selenium import webdriver
import datetime
import os
import pytesser
import sys,time
from PIL import Image
reload(sys)
PostUrl = "http://seat.lib.whu.edu.cn/login?targetUri=%2F#"
driver=webdriver.Firefox()
driver.get(PostUrl)
def image_file_to_string(file):
cwd = os.getcwd()
try:
os.chdir("C:\\Python27\\Lib\\site-packages\pytesser")
return pytesser.image_file_to_string(file)
finally:
os.chdir(cwd)
def tryy():
# 對驗證碼進行區(qū)域截圖
driver.get_screenshot_as_file("C:\\Users\\yingtaomj\\PycharmProjects\\test\\image.jpg") # 比較好理解
im = Image.open('C:\\Users\\yingtaomj\\PycharmProjects\\test\\image.jpg')
box = (950, 324, 1058, 357) # 設置要裁剪的區(qū)域
region = im.crop(box) # 此時竹习,region是一個新的圖像對象。
region = region.convert('RGB')
region.save("C:\\Users\\yingtaomj\\PycharmProjects\\test\\save.jpg")
im = Image.open("C:\\Users\\yingtaomj\\PycharmProjects\\test\\save.jpg")
code = image_file_to_string("C:\\Users\\yingtaomj\\PycharmProjects\\test\\save.jpg") # code即為識別出的圖片數(shù)字str類型
print code
# 打印code觀察是否識別正確
elem_user = driver.find_element_by_name('username')
elem_psw = driver.find_element_by_name('password')
elem_code = driver.find_element_by_name('captcha')
elem_user.send_keys('學號')
elem_psw.send_keys('密碼')
elem_code.send_keys(code)
#代碼不夠完善列牺,有時會讀取成標點符號報錯整陌,只能重新運行一下
#驗證碼不一定識別正確,因為要循環(huán)識別直到成功
while True:
tryy()
try:
driver.find_element_by_name("password")
except:
break
driver.find_element_by_link_text("常用座位").click()
buytime='2017-07-12 22:30:00'
startime='09:00'
endtime='21:00'
while True:
now = datetime.datetime.now()
#十點半啦瞎领!開始搶座啦泌辫!
if now.strftime('%Y-%m-%d %H:%M:%S') == buytime:
driver.find_element_by_id("display_onDate").click()
driver.find_element_by_xpath("http://a[@value='2017-07-12']").click()
driver.find_element_by_id("seat_6145").click()
#圖方便只能在常用座位選,每個座位都有自己的id "seat_xxxx
try:
driver.find_element_by_link_text(startime).click()
driver.find_element_by_link_text(endtime).click()
driver.find_element_by_link_text("預 約").click()
except:
driver.find_element_by_link_text("取 消").click()
#如果第一個沒搶成功就看第二個
driver.find_element_by_id("seat_6172").click()
#不sleep一下程序有可能報錯
time.sleep(0.5)
driver.find_element_by_link_text(startime).click()
time.sleep(0.5)
driver.find_element_by_xpath("/html/body/div/div/div[3]/dl/ul/li[2]").click()#li的序號是多少取決于想訂到幾點
time.sleep(0.5)
driver.find_element_by_link_text("預 約").click()