from selenium import webdriver
from urllib.parse import unquote
from selenium.webdriver.common.action_chains import ActionChains
import time
import requests,json
import re
import cv2
import string
import base64
num=int(input("请输入小号个数"));
def bcimg():
js= 'return document.querySelector("body > div.tobe-obfuscate-slide-main > div.tobe-obfuscate-slide-box.sncaptcha-jigsaw > div.tobe-obfuscate-slide-wrap > div.tobe-obfuscate-image-wrap > div.tobe-obfuscate-image-wrap-box > img").style.display="none";'
browser.execute_script(js)
time.sleep(1)
browser.find_element_by_xpath("/html/body/div[7]/div[2]/div[2]/div[1]/div[3]/canvas").screenshot('.\\shibie\\big.png')
small = browser.find_element_by_xpath('/html/body/div[7]/div[2]/div[2]/div[1]/div[3]/img').get_attribute("src")
smalla = requests.get(small)
with open(".\\shibie\\small.png", "wb") as fp:
for data in smalla.iter_content(128):
fp.write(data)
def identify_gap(bg,tp,out):
bg_img = cv2.imread(bg) # 背景图片
tp_img = cv2.imread(tp)
bg_edge = cv2.Canny(bg_img, 200, 250)
tp_edge = cv2.Canny(tp_img, 200, 250)
bg_pic = cv2.cvtColor(bg_edge, cv2.COLOR_GRAY2RGB)
tp_pic = cv2.cvtColor(tp_edge, cv2.COLOR_GRAY2RGB)
res = cv2.matchTemplate(bg_pic, tp_pic, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
th, tw = tp_pic.shape[:2]
tl = max_loc
br = (tl[0]+tw+5,tl[1]+th+5)
cv2.rectangle(bg_img, tl, br, (100, 75, 255), 2)
cv2.imwrite(out, bg_img)
return tl[0]
def huakuai():
print('保存图片');
bcimg();
time.sleep(2);
print('识别图片');
bg='.\\shibie\\big.png'
tp='.\\shibie\\small.png'
out='.\\shibie\\a.png'
zuobiao = identify_gap(bg,tp,out)
print('识别坐标:'+str(zuobiao))
slider = browser.find_element_by_xpath('/html/body/div[7]/div[2]/div[2]/div[2]/div/div[3]')
print('按下滑块!')
ActionChains(browser).click_and_hold(slider).move_by_offset(zuobiao+8,0).release().perform()
print('滑块结束!')
while num > 0:
print(num)
browser =webdriver.Chrome()
browser.get("https://passport.suning.com/ids/login?service=https%3A%2F%2Faq.suning.com%2Fasc%2Fauth%3FtargetUrl%3Dhttps%253A%252F%252Fmsinode.suning.com%252Fm%252Fhome.do&loginTheme=wap_new");
time.sleep(2);
# browser.find_elements_by_class_name('clo-se').click();
# time.sleep(1);
# browser.find_element_by_xpath('/html/body/div[3]/div[7]/a[5]').click();
# time.sleep(2);
tel='13351122211';
browser.find_element_by_id('phoneNum').send_keys(tel);
time.sleep(2);
# sour = browser.find_elements_by_class_name('tobe-obfuscate-slide-main');
# print(len(sour));
# print(222);
# browser.find_element_by_xpath('/html/body/div[1]/div[6]/a').click();
browser.find_elements_by_class_name('getYzm')[0].click()
time.sleep(3);
sour = browser.find_elements_by_class_name('tobe-obfuscate-slide-main'); #判断是否有滑块
# print();
if len(sour)>0:
print('出行滑块');
huakuai();
time.sleep(5)
pdstyle = browser.find_element_by_class_name('tobe-obfuscate-slide-main').get_attribute('style')
print(pdstyle)
if pdstyle=='display: none;':
print('滑块已过');
hka = 'aaa'
if hka!='aaa':
print('手动过滑块后输入1继续')
hka = int(input());
# browser.close()
# continue
yzm = input("请输入验证码"); #这里可以对接接码
browser.find_element_by_id('yzminput').send_keys(yzm);
time.sleep(2);
browser.find_element_by_xpath('/html/body/div[1]/div[9]/a[1]').click();
time.sleep(2);
cookies = browser.get_cookies()
print(cookies)
fo = open("cookie_suning.txt", "a")
fo.write(cookies+"\n")
fo.close()
num=num-1
browser.close()
time.sleep(2)