企查查登录验证(selenium)

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
from PIL import Image
import time
import pygame



# 汉字转化成图片
def chinese_to_img(text):
pygame.init()
# text = u"文字转图片"
font = pygame.font.SysFont('simhei', 16)
ftext = font.render(text, True, (65, 83, 130), (255, 255, 255))
pygame.image.save(ftext, "image.png") # 图片保存地址

driver=webdriver.Chrome()
driver.get("https://www.qichacha.com/user_login")
driver.find_element_by_id("normalLogin").click()
driver.find_element_by_id("nameNormal").send_keys("17320180454")
driver.find_element_by_id("pwdNormal").send_keys("17320180454")

# 移动鼠标
time.sleep(1)
move_k=driver.find_element_by_id("nc_1_n1z")
ActionChains(driver).drag_and_drop_by_offset(move_k,341,0).perform()
time.sleep(2)

# 截取图片
driver.save_screenshot('bdbutton.png')
element = driver.find_element_by_xpath('//*[@id="nc_1_clickCaptcha"]/div[2]/img')
print(element.location) # 打印元素坐标
print(element.size) # 打印元素大小
left = element.location['x']
top = element.location['y']
right = element.location['x'] + element.size['width']
bottom = element.location['y'] + element.size['height']

im = Image.open('bdbutton.png')
im = im.crop((left, top, right, bottom))
im.save('bdbutton.png')

text=driver.find_element_by_xpath('//*[@id="nc_1__scale_text"]').text
chinese_to_img(text)




# 合并图片
import win32print
import win32ui
import win32con
from PIL import Image, ImageDraw, ImageFont, ImageWin, ImageColor
import os
def merge(image1, image2):
'''
实现垂直合并两张图片
@param image1: 需要合并的第一张图片
@param image2: 需要合并的第二张图片
'''

w1, h1 = image1.size
w2, h2 = image2.size
target = Image.new('RGB', (w1 if w1 > w2 else w2 , h1 + h2), (255, 255, 255, 0))
temp = image1.resize((w1, h1), Image.ANTIALIAS)
target.paste(temp, (0, 0, w1, h1))
temp1 = image2.resize((w2, h2), Image.ANTIALIAS)
target.paste(temp1, (0, h1, w2, h1 + h2))
target.save('merge.png')
if __name__ == '__main__':
printer_name = win32print.GetDefaultPrinter()
print(printer_name)
merge(Image.open('image.png'), Image.open('bdbutton.png'))
if os.path.exists("merge.png"):
import chaojiyings
chaojiying = chaojiyings.Chaojiying_Client('1234567890', '1234567890', '96001') # 用户中心>>软件ID 生成一个替换 96001
im = open('merge.png', 'rb').read() # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
x=int(chaojiying.PostPic(im, 9101)["pic_str"].split(",")[0])
y=int(chaojiying.PostPic(im, 9101)["pic_str"].split(",")[1])
time.sleep(1)
move_m = driver.find_element_by_xpath('//*[@id="nc_1_clickCaptcha"]/div[2]/img')
ActionChains(driver).move_to_element_with_offset(move_m, x, y-17).click().perform()




posted @ 2018-09-27 18:01  MISF  阅读(2832)  评论(0编辑  收藏  举报
     JS过度和变形效果演示   
  
    html5.png